The State of SwiftUI: Finally Ready for Production?
SwiftUI is undoubtedly the future of building user interfaces for all of Apple's platforms. The question many developers are facing is whether it is now in its 4th revision finally production-ready. After all on one side you do not want to continue to invest in "old" technology, but on the other side you also do not want to get "stuck" in the development process because something is not quite "there" yet.
We faced this very question twice in the last two years at Elemental Tools:
- In mid 2020 we did a quick prototype for our latest app Infos with SwiftUI 2, but quickly abandoned the idea, since it was definitely too early for a "real" app and instead went for native UIKit / AppKit instead
- Last year after WWDC 2022 we again did a prototype for the next generation of Firetask we are currently working on. This time the story was different: SwiftUI 4 turned out to be a game changer -- especially for desktop-class apps the framework had taken a giant leap forward
So is this already the answer? Is SwiftUI finally production-ready? There are a lot of opinions out there and it seems half of the people say yes and the other half no. My personal opinion is: it depends.
We have spent the last four months prototyping all aspects of our next generation user interface for Firetask 5 with SwiftUI 4 across platforms (mainly iOS, iPadOS, macOS -- as watchOS should be easy). Why did we do this? Because we wanted to use the latest technology, but we also did not want to get stuck somewhere later on.
First of all I have to say that nearly everything which was still a total mess in 2020 has been fixed and we could build most parts of the UI very quickly using built-in functionality. I personally was especially impressed with the progress in the following areas (disclaimer: now it gets really technical -- if you have no programming background you might want to skip to the last paragraph ;-):
- Custom layouts with the new
Layoutprotocol are great -- the only small thing that is missing is the possibility to hide views - The general focus management of SwiftUI with the
focusedmodifier works quite well - Forms are now very consistent across platforms with platform-native behavior (only on the Mac we would have liked more flexibility)
- The overall layout mechanics have become very exact and predictable (also across platforms)
On the other side we encountered a number of weird detail design decisions and limitations (interestingly mainly on iPadOS and macOS) that I really cannot understand, for instance:
- It is basically impossible to create a custom focusable view with SwiftUI. There is a
focusablemodifier, but on the Mac it only works if full keyboard access (in System Settings) is enabled and on iPad it is not available at all - There is a new way to set a default focus, but again it does not work cross-platform (only on Mac and tvOS), why?
ScrollViewReaderis still too limited -- no built-in way to get the current content offset and no way at all to scroll to a specific point- Finally,
LazyVStackandLazyHStackare great, but there is no built-in selection or focus management limiting their out-of-the-box use for complex use cases (at least on the Mac)
The last one might be more complicated to implement for Apple, but the first three limitations are only by design for whatever reasons. The result is that you have to use the UI/NSViewRepresentable protocol much more often than you would like to implement functionality yourself that would be built-in and ready to use if you decided for a native UIKit / AppKit app. Especially since Apple seems to be eager on pushing iPadOS for desktop use cases (e.g. Stage Manager) and iPad sales are growing ($9,3 billion in Apple's Q1 vs $7,2 billion a year ago), it is irritating that so many keyboard focus related use cases are not supported on iPad in SwiftUI.
So what is my personal, final verdict? SwiftUI 4 is a major step in the right direction and it may be production-ready depending on your specific use case. My suggestion would be to use the following guidelines to decide on whether to use SwiftUI, or not:
- Definitely use SwiftUI if you build an iPhone and/or watchOS app and you can target iOS 15 / watchOS 7 or later
- Use SwiftUI if you build a simple to medium-complex app for iPadOS 16 or macOS 13 Ventura
- Consider using SwiftUI for building a complex iPad or Mac app if you can target iPadOS 16 / macOS 13 Ventura, but be aware that you will still have to invest quite some time in building workarounds for things that would be easy in native UIKit/AppKit apps.