I hate to say it but SwiftUI is tricky to write for very complex user interface...the one in that file is a nightmare imo.
It could also use actual comments, and perhaps breaking more things putout into subviews.
It is the fully working safari UI in only 1000 lines of code. Additionally the declarative approach of SwiftUI together with the type system makes it certainly correct in many ways: no rendering bugs, no invalid states, probably no memory leaks, no cyclic dependencies creeping in.
Try to build this in Java Swing, UIKit, Html/Css/Js or any other UI library. Flutter might come close, react/vue/svelte as well, if you assume sensible predefined components. But they work similar to SwiftUI and the resulting one-file might look pretty similar.
I have an old editor written in Java/Swing that takes more and more willpower to work on every time because handling state update bugs is what i spend half my time on.
A lot of this would be broken out into it’s own file (e.g. extensions on basic types like Arrays would go in Array+Extensions.swift). Each view would go in its own file. You would break out code into separate functions instead of inlining it inside closures in the view body.
SwiftUI (though not usually Swift in general) does have a problem with over-indentation IMO. You barely have to go more than 3 levels deep in the view hierarchy you are producing before your code feels like more white space than code.
I find that an insane project for a teenager. I certainly couldn't have pulled it of.
Reminds me of the PHP4-5 days where we'd have complex logic right within HTML components.
You don't have to (and almost certainly shouldn't) write it like that.
Of course, this is just a project for fun so if this person can figure it out, more power to them. It's a neat project.
Generally it’s better to compose views, by that I mean you often have to because of the compiler. I’m surprised this file even compiles! The Swift compiler usually chokes on much smaller views.
Just a personal opinion here, but those shared state objects and SwiftUI + glorified singletons really hurts every time I see it. It's so prevalent in online tutorials like Ray Wenderlich and the such.
Honestly, it's hard to avoid and can be done but requires a significant effort. I was hoping for Apple to come up with a more elegant solution during WWDC 21 but so far I haven't seen anything to improve this situation.
While this case I'm in 100% agreement with you, in my experience I don't think I've ever seen any people I know like changes to icons!
I haven't used an Apple mobile product in years (just Mac's for work), but damn did this hit me with some nostalgia.
That’s exactly what the author did. It’s like a “learn to build X clone” but for many different X’s.
With that said, he really needs to delete those .DS_Store files scattered everywhere in his repo. Ouch.