SwiftUI or StoryBoard in Swift?

9o8d...huRx
19 Nov 2023
94

The debate between SwiftUI and storyboards revolves around whether it is preferable to use a GUI to create a GUI. This has been a topic discussed since Steve Jobs introduced Interface Builder in 1992. GUI builders like Xcode's Interface Builder allow for the creation of GUI elements through drag-and-drop, but lack the ability to design dynamic GUIs and generate data files that aren't suitable for source code control systems. On the other hand, manually coding GUI components is time-consuming. SwiftUI serves as a compromise, requiring manual coding of GUI components but providing immediate visual feedback similar to Interface Builder without the need to keep XML files in source control.


Comparing SwiftUI vs. Storyboard

The following table compares SwiftUI versus storyboard from a software engineering perspective. 
SwiftUI is better because it has six points in its favor, versus storyboard having three points. 

Exceptions Where Storyboards Are Better

There are situations when storyboards are preferable. For example, you might want to use storyboards when you need rapid results and merge conflicts are non-issues. You might also need to use storyboards when you’ve reached the end of SwiftUI’s support. 
You can prototype user interface flows rapidly with storyboards. You can design how multiple screens interconnect and have an overview of the possible flows in Xcode’s storyboard editor. Alas, SwiftUI previews can’t do this (yet), as it doesn't show a map of screen flows. 
Another reason is to cater to edge cases solvable through storyboards but not SwiftUI. Fortunately, the storyboard is still available to help. 

Does SwiftUI Replace Storyboard?

SwiftUI can replace storyboards if your deployment target is iOS 14 or later, but there's no indication that Apple will deprecate storyboards.

Can You Use Storyboard With SwiftUI?

You can mix UIKit with SwiftUI components in an iOS app, and you can also use storyboards alongside SwiftUI.

Next Steps

Use SwiftUI instead of a storyboard for your new UI components. Nevertheless, you aren't compelled to migrate existing storyboards to SwiftUI. Remember that storyboard was introduced over a decade ago, having roots tracing back to NeXT’s Interface Builder in 1992. Then Lindy’s law says it would be around for another decade. 

Write & Read to Earn with BULB

Learn More

Enjoy this blog? Subscribe to CryptoPemp

7 Comments

B
No comments yet.
Most relevant comments are displayed, so some may have been filtered out.