It has been a month and a half since SwiftUI came out, and like every year, when Apple announces it’s multiple (overwhelming) updates for developers like me, I promised myself I was going to get ahead of time and learn it right away (yeah just like iOS developers version of New Years Eve resolutions), truth is… I didn’t. So today I took my first dive into it and wanted to make it easier for anyone who still hasn’t had the time to review it, because let’s be honest, at the moment, it is not required in our every day, but it will someday be. As the title states, this comes from my first glance into SwiftUI.
The first thing I found out (and which sidetracked me in the beginning), is that you need macOS Catalina and Xcode 11. Back then, Catalina was still in Beta and I didn’t want to deal with those bugs in my projects. But now it is available and you only have to have a bit of patience to install both things if you don’t have them already. If you have that, you are good to go.
What is SwiftUI
I don’t know about you, but in my opinion, sometimes it puzzles me why Apple keeps changing things, while their devices remain the same (almost) every year. This answer covers several points:
1. SwiftUI unifies user interface frameworks
SwiftUI is the next version of user interfaces for Apple Development. What is different from the previous methods (XIB and Storyboards) is that it provides unification among the different UI Frameworks: UIKit (iOS and TVOS), AppKit (MacOS), and WatchKit (WatchOS), explaining the differences among these frameworks is a topic in itself that would require a post in itself, personally, I never cared for the differences among them as most clients always require apps for iOS and TVOS.
2. It has dynamic previews
I think an image explains this better than words:
Important things to note in the above picture:
a) This preview pauses often (for example when you run a build) and you can’t interact with it while it’s paused.
b) You can cmd+click on objects/views to get a menu with options
c) Code can seem very confusing at first, but if you have experience with Swift you will start understanding it soon enough.
d) You need a big screen! I know most developers work on separate monitors, but I personally like working only on the laptop’s screen and it is harder every time.
3. It incorporates ‘state’ control in the UI
In summary, you can bind a view to the corresponding state (this is a bi-lateral connection) and whenever the state gets updated, the view renders again, and vice-versa, if the view updates, it can change the corresponding state.
4. We can finally edit the code of our views
I think this was much needed in Apple’s development platforms, one of the biggest downsides of developing in this platform, in my opinion, was the strongly bonded it was with Interface Builder. Although it is a great tool, and it has made great progress since when it was first introduced, I highly doubt there is a developer who had not found himself/herself annoyed with a merge conflict due to a small change in IB. Now with SwiftUI, we know which part of the code refers to the interface, and I hope this will make our lives easier. Now you don’t have to choose between ‘code’ views vs ‘IB’ views.
SwiftUI seems like a promising tool for iOS developers. It unifies UI frameworks of Apple, which will allow us to develop cross-platform apps more easily. This new tool also is part of the ‘state’ driven development area, which is a trending topic within developers. You can preview your app UI in a very similar way as you did previously with XIBs and Storyboards, but with the advantage that you can see and edit the code, it is generating.
For this topic, you have the usual resources, and I may not list them all, but I will add some that caught my attention:
This repo was released right after the announcement of SwiftUI and it has collected a huge amount of the information out there on SwiftUI, take a look at it if you want a wide variety of options.
If you liked the content on this post, please follow me at the bottom of the page. You can also buy me a coffee to support me!
Until next time!
Evana Margain Puig
If you need any services regarding mobile apps please come to my webpage, evisoft.mx or drop me a line email@example.com.