SwiftUI cons: Why I don't use it in production
After several months of trying SwiftUI in my apps, I decided to list some concerns which keep me away from using it in production. Even if you're hyper-optimistic about it, it's still healthy to know its downsides and potential drawbacks it may cause in the work of a mobile developer.
SwiftUI is a big step for Apple and iOS, macOS & iPadOS developers. It brings a lot of new possibilities, a completely different approach to building views, faster reloads etc. The toolkit will for sure be developed in next years, but right now isn’t yet mature. This is why besides many pros, there is surely a blot on the landscape. Or two. Let’s then focus on the most important cons of SwiftUI.
Right now, with iOS 13, macOS Catalina and iPadOS, SwiftUI is a brand new yet immature technology. I tried
SwiftUI on a few test apps, and on one production app as well. While I’m sure that in the next years it will be developed and get much better, I’m not going to use it - at least this year. Why?
No backward compatibility
First, because it lacks backward compatibility. SwiftUI is supported only on iOS 13 and higher. Even if this version of mobile OS is used by most iPhones & iPads, it still isn’t by all of them. There are still many iOS-12-and-lower devices. So if ordinary people are using your app, there is a big possibility, that some of them are using earlier versions of iOS. If you don’t want to lose this audience, the answer about SwiftUI is clear.
The second thing is hot reloading. In theory it looks great, but the reality (Xcode 11) isn’t so bright. For me, the hot reload works in most cases, but sometimes stops in the most unexpected moments. Sometimes it doesn’t work with pieces of code that just look good. Even if the feature doesn't work, you can still carry on buildin the app, but then… you lose the advantage of one of Swift UI's most important features.
Error messages are frustrating („ambiguous without more context” is my favorite one). Want to debug your code? You won't get much information. Especially when you want to debug errors. The SwiftUI preview module doesn’t provide good error messages. Even worse, they are often misleading. So you need to Google errors on your own. And you get even more frustrated because still there are not so many solutions available on the Internet. Still, Apple documentations or even WWDC video materials are the most reliable information resources. Of course, if you have enough time to watch them.
UICollectionView. You can build Lists (
SwiftUI equivalent of
UITableView), but there is no
Collection Views. Why? Partly because in
SwiftUI you can build small elements and then populate it, and partly because Apple didn’t solve it yet. So if you don’t want to implement your own solutions, you are stuck on using third party ones (CocoaPods etc.). Which isn’t the best way to solve the problem.
Last but not least, using
SwiftUI is associated with a bit different approach to building projects, e.g. using Scenes. And this is something that needs some time to get used to. I’m sure that it will improve in next iterations of
SwiftIUI and iOS, but just like other things in
SwifUI - it just needs time.
Swift UI - to use or not to use?
I think the best solution for now is to wait. Maybe with iOS 14
SwiftUI will be mature enough to use it in my projects. Currently, I've been using the toolkit only to learn its specifics, gradually adding it to my existing project. There is
UIHostingViewController which is worth recommending for existing apps. So when the right time comes, I’ll be prepared. And I'm convinced you should be, too.