Is leaving Storyboards for SwiftUI right? In this article, I am explaining it is. Although the framework is still immature, iOS developers should already think of making a switch. Here's why.
Last time, I was writing about SwiftUI's cons. Despite its pros like declarative syntax, live preview and adding components with drag and drop, Apple's new toolkit for building user interfaces also comes with disadvantages. Most of them, like no backward compatibility & hot reload, stem from SwiftUI's relatively young age. Then it's just a matter of time that its next iterations will bring refinements of its features.
Building views without Storyboards
Recently, I've watched the Let's build this app channel on YouTube. The way Brian Voong builds applications got my attention:
- No Storyboards,
- No XIBs,
- Just pure code.
Pure code, you may be asking. Yes, Voong's solutions are easy, crystal clear and, in my opinion, more efficient.
This helped me leave Storyboards behind and start writing views programmatically, on my own. Currently, I have been using this method in a chat application for clients, containing form options. When I wanted to add dynamic
UITableView with custom cells, I was amazed how easy it was to prepare them with pure code.
Results of writing views programmatically:
- Clearer code,
- It's easier to implement global changes.
Need an example? Last time, I needed to change all fonts in one of my projects. So far, doing things like these in Storyboards was a pain in the neck. With views generated programmatically - easy peasy. Same if I want to reuse some views. No way to avoid problems when doing this in Storyboards.
Will SwiftUi win over Storyboards?
This is why I started to think about moving my projects to SwiftUI lately.
Sure, it's still not mature, and iOS 13 is the only iOS that supports it. But I'm also pretty sure that next year the situation will look different.
Apart from that, new tools are showing that help us move Storyboards projects to SwiftUI. Take the Objective2Swift converter for example. While as far as I've checked, it is not 100% trouble-free, it’s still a great way to start updating your app. In the next weeks I’m going to test it more thoroughly.
Although it's still a bit early for many existing projects to jump on the SwiftUI bandwagon, more opportunities are appearing. And I think this is just the beginning. I’m sure SwiftUI will get more functions this year - Apple is going to push to make it more accessible and eventually,a global approach for building views.