3 Reasons Why I don’t like using SwiftUI

ohdarling
3 min readApr 23, 2022

--

SwiftUI is popular, but sometimes I don’t like using it, why?

Hidden Unknown Styles

All controls in SwiftUI have their own default style, for example, VStack and HStack will only stretch with the size of its content, but in other languages, the container will automatically fill the parent container by default.

Therefore, in SwiftUI, we should pay attention to the layout, otherwise it will not perform as we expected. Due to this reason, we will need more code to make it works.

Also, SwiftUI has some decorator methods without parameters, which may behave differently than than we expected, take a look at the following example:

When we don’t add .padding to the second HStack, the two HStack are laid out closely one-to-one, but when .padding is added to the second HStack, there is some strange space between the two HStack.

It’s strange, if we need to solve this problem, we need pay more time to solve it, I don’t like this.

Bridging Controller Needed

SwiftUI is a nascent UI framework on iOS which introduced on 2019, it has been developed for three years, there are many controls and UI design patern in SwiftUI, such as NavigationLink as a navigation target. But on the other hand, there are more controllers in UIKit that provide a complete iOS experience.

For a simple app, using table, tab, navigation is enough, all controls for that purpose are ready. But if you want build some complex app, like a Video Player, you must use a UIViewControllerRepresentable to bridging controller in UIKit to SwiftUI, then, it’s boring.

If I need a lot work to make UIKit works in SwiftUI, why not using UIKIt directly? I don’t like this.

Better Preview, Worse Experience

Xcode offers a new instant preview feature for SwiftUI views, which provides preview without having to build and run the app in simulator or device. It sounded wonderful before using it.

However, if we write some complex SwiftUI views, Xcode will failed to compile that view and will not provide a preview for that view, which will spend a lot time to struggle with the SwiftUI compiler. It is a waste of time, I don’t like this.

Conclusion

While SwiftUI has many inconveniences, and SwiftUI requires a high iOS deployment version, I think SwiftUI provides an easy way to make user interface and an easy method to manage state of user interface.

Some missing components in SwiftUI such as picker, textfield, we can use third-party libraries such as SwiftUIKit, to bring us a better SwiftUI development experiences.

So, though SwiftUI is not perfect, it is worth a try!

Thanks for reading.

--

--