by happytoexplain · 2y ago · 0 comments
The same story many experienced with SwiftUI vs UIKit. Apple has flubbed the move to declarative APIs hard. It's a scary experience committing to these APIs, because of the wild changes they experience, the performance issues, and the fact that they are borderline un-debuggable by the average mind compared to imperative APIs, so when you run into real trouble, you're often kind of just fucked. And it's not even like normal 1st party frameworks where the bug is virtually always in your code. With these, sometimes the bug really is Apple's.
I wish these things didn't have "Swift" in the name, since their problems have nothing to do with the language as far as I can tell, and they make Swift look bad.
That this is the best the richest company in the world can do with the API to their most valuable product is quite astonishing.
But then I hit a "Unable to infer complex types" error in SwiftUI, and think maybe the Google folks got it right after all.
These should really be open source: it's such a waste of time to have to experimentally poke around to see how the SwiftUI components interact with their UIKit counterparts, when these should really just be straightforward wrappers.
In many cases, the declarative APIs are just poorly thought out and/or clearly not "battle tested", and there is a lot of API churn in really crucial components which are also often not backported to older OS versions.
It's funny, when SwiftUI and Compose were coming out we waited a bit but jumped in as soon as we could. With Compose, our early versions required us to make builds of Android Studio on our own machines that supported it. But even then Compose felt more polished in a lot of ways - and if we ran into issues we could _see the code_ and make our own components with the changes we needed if necessary.
SwiftUI is great, really, but has so many rough edges, gotchas, and bugs. They do get fixed, but you're still supporting 4 year old versions of iOS without those fixes, so you're screwed.
Just completely boneheaded not to open source SwiftUI from the start, especially with how great the open source Swift community is.
The worst offenders by far are the scroll & list views, which are basically useless. As a starting point, there is no way to get the current scroll position from a scroll view in iOS <18.
So yes, I often have to wrap the UIKit components myself, and deal with all the joys of UIKit I was hoping to finally avoid...
Apple did exactly the right thing with Swift itself: the Swift forums are excellent, and it's clear that Apple employees use these to prioritize the (very real) Swift bugs and limitations. Why does this not exist for SwiftUI?
I can’t imagine how it could be implemented more simply.
Even if you are rendering a complex chain of compute shaders with multistage heap fences onto a process shared IOSurfaceRef with several concurrent threads greedily realiasing your scratch buffer to queue up more work, it doesn’t matter. Eventually you’ll up with a UIView or CALayer and it’s still just one function call to bring it into SwiftUI.
SwiftUI has the unfortunate combo of being closed-source, being platform-dependent, and being buggy in the most unusual ways. Which is a shame, because SwiftUI has a lot of good things going for it.
In my experience, the trick is making small tested and working views, and combine these into fullly-fledged screens.
In the present, Apple has beautiful hardware and sucky hardware.
No idea when they will get both beautiful hardware AND software.
(Frankly, I preferred good old, stable Objective-C - Apple ditched the KISS principle, when they adopted Swift).