A Healthy Comparison between SwiftUI and Storyboard

Storyboard

Storyboard is a part of an interface builder which has been the most common way to create UI for iOS applications after its initial release with iOS 5. Any new iOS project has a Main. storyboard file by default.

 

“The Interface Builder editor within Xcode makes it simple to design a full user interface without writing any code. Simply drag and drop windows, buttons, text fields, and other objects onto the design canvas to create a functioning user interface.”

-Apple documentation about interface builders.

A Storyboard in Xcode is a file that contains an empty canvas type screen. On it, we can drag and drop all types of objects available in the object library of Xcode. 

We can create almost everything from controllers to text fields to images to table views to buttons, all this without writing even a single line of code. You can add controller screens like a table view controller, navigation controller, etc. through drag and dropping from the object library. 

 

You can add segues and move through different screens. Even the smallest components like labels, images, text fields can be dragged and dropped from the object library.

Advantages of Storyboard:

  • It is easy to learn for even a beginner.
  • With Storyboard, you can create a prototype of an app barely in an hour or two, which makes it easy to visualize the app without writing hundreds and thousands of lines of code.
  • The storyboard object library has a vast collection of objects.
  • It also has a large community support network.

Drawbacks of Storyboard:

  • Source control is difficult, since the storyboard code is in an XML type format it is very difficult to resolve merge conflicts as you cannot completely understand the code.
  • While creating the application UI you have to keep in mind the Autolayout issues that they should work with all the supporting device sizes, you need to separately check on all devices using the preview option or running the app on each device.
  • As the number of screens keeps increasing the management of storyboards can become very chaotic and as it forms a complex web-like structure.

Swift UI

Swift UI was released with the release of iOS 13.

“SwiftUI helps you build great-looking apps across all Apple platforms with the power of Swift — and as little code as possible. With SwiftUI, you can bring even better experiences to all users, on any Apple device, using just one set of tools and APIs.”

-Apple documentation about swift UI.

Swift UI is basically a toolkit released by apple to create UI’s in a declarative way.

Advantages

  • A single code can be used for all apple platforms like macOS, watchOS, iOS, etc.
  • It offers an automatic live preview option which is like a hot reload that shows the changes made in the code immediately on view.
  • There are no Autolayout issues as in the storyboard.
  • It offers both drag and drops through the object library as well as writing code in the file facility.
  • The code is simple and clean.
  • Swift UI view elements can be easily reused, by creating smaller module files.
  • It gives way to reactive programming by providing bindable objects.
  • You can also mix UIKit and SwiftUI by using UIHostingController.

Disadvantages

  • It supports only iOS 13+ and Xcode 11+, so you cannot build lower version apps using this.
  • It is still very new, there are not as many component options in the swift UI as in the storyboard object library. So you have to create custom views to fulfill requirements, eg: The search bar.
  • It could be difficult for someone to switch from storyboard to swift UI as it is difficult to visualize the view hierarchy in the form of code.
  • There is no direct way of migrating from storyboard to swift UI. This compels a developer to continue the use of the storyboard for existing apps and in lower versions.
  • Since it is very new so there is less community support which is not the case for Storyboard.

After looking at the pros and cons of both Storyboard and SwiftUI, building an app UI using storyboard is comparatively easier for a beginner, and has been for a very long time. But there are some flaws with it and those flaws have been taken care of in Swift UI.

Swift UI also has its own set of flaws, but it can be seen that those flaws can be overlooked in terms of the advantages that it gives. Swift UI has a lot of potential for the future. 

You can also take a look at this Single view iOS application using swift UI if you want a taste of a SwiftUI application: iOS application using SwiftUI GitHub link.

About the Author

Smriti Arora is a young and passionate software development engineer and technical blogger with a knack for simplifying the technologies she works on for her readers. When she’s not writing or coding, she can found with loud music, setting the scene as she scours the internet in for tasty recipes and unique things to explore.