Boom .. here is it .. this thing Apple announced at the WWDC2019 and the reason why the whole iOS development community is going mad.
If you are into iOS development, you probably heard about SwiftUI in the last days. Everybody is writing about it and everyone is really excited. But at this very moment there are not many resources about SwiftUI und many are confused by it. But be sure, after reading this guide, you’ll know exactly what SwiftUI is about and how to get started using it.
What is SwiftUI?! 🤯
First of all, let’s talk about what SwiftUI is and what it is used for. Apples describes its new innovation as follows:
“SwiftUI is an innovative, exceptionally simple way to build user interfaces across all Apple platforms with the power of Swift.”Apple
So basically, SwiftUI is a completly new way of building user interfaces for apps. Until now the most common way to build the UI in Xcode was to use storyboards and XIB files. With SwiftUI, Apple provides an alternative to these.
With SwiftUI you can build your app by using a new declarative syntax. With this you describe how your interface should look like and what it should do.
You see that the syntax really differs from what you saw before in iOS programming. This is because it follows a declarative approach instead of an imperative one. Imperative programming was the common programming approach. But what’s the difference? In a nutshell: With imperative programming we write how we react when the state of our app changes, and accordingly execute code. With declaraive programming instead, we describe the interface of our app for all possible states in advance. Here’s a great article if you want to dive deeper.
In addition to a more simple and intuitive syntax, with SwiftUI Xcode finally serves us with a live preview while building the app’s UI. Everything we write will be instantly be shown our live preview which saves us much time compared to building the app and running it in the simulator every time.
Not only do we have a live preview with SwiftUI while writing our code, we can even edit our interface in the preview, which affects our code immediatly. This link between code and preview makes programming with Swift and Xcode even easier and more intuitive.
There are some more advantages coming with SwiftUI:
- Connection similar to outlets and actions you know from using storyboards are permanently checked by the compiler. So no runtime errors anymore due to lost connections!
- SwiftUI makes it easy to develop for mutiple platforms like iOS, macOS, watchOS etc.
Are storyboards dead? 😵
To keep it short: Storyboards aren’t dead. As the past has shown, Apple isn’t throwing away established concepts overnight. A comparison: Meanwhile it is 5 years ago that Swift replaced Objective-C as the main programming language for iOS development. Nevertheless, iOS apps can still be written in Objective-C without any problems. What we can assume, however, is that Apple will focus strongly on interface development with SwiftUI in the future. So although it will take time to establish (SwiftUI will be officially released together with Xcode 11 this fall), we recommend you to get in touch with it.
The same applies to UIKit, including UIViewControllers. With SwiftUI it’s still possible to include the different objects of the UIKit and to integrate them into SwiftUI.
“SwiftUI works seamlessly with the existing UI frameworks on all Apple platforms. For example, you can place UIKit views and view controllers inside SwiftUI views, and vice versa.”Apple
How do I run SwiftUI? 🏃♀️
SwiftUI comes with Xcode 11 which will be published this fall. However, SwiftUI is already available as part of the beta version of Xcode 11.
Currently, there are two ways to run SwiftUI:
1: Mac OS XY (Catalina) beta + Xcode 11 beta
In order to use SwiftUI properly, you need to run the Xcode 11 beta on a Mac with MacOS Catalina, which is currently only available as a beta version too.
Here’s a great tutorial on how to install MacOS Catalina beta and Xcode 11 beta!
2: MacOS Mojave + Xcode 11 beta (limited possibilties)
If you don’t want to switch to Catalina beta, you can still explore SwiftUI in Xcode 11 running on a Mac with Mojave.
This option does not offer you all the features of SwiftUI, but lets you try out the basic concepts.
Here’s a great video on how to achieve this!
How do I start learning SwiftUI? 📚🤓
Now you are probably excited and want to get started with SwiftUI right away. Here are some resources to help you explore and learn SwiftUI.
- BLCKBIRDS: We published own tutorials about making apps with SwiftUI. More stuff coming very soon! 🔥
- Tutorials by Apple: Apple provides some very great and helpful tutorials on how to get started with SwiftUI.
- Hacking with Swift: Paul from Hacking with Swift already published a lot of information about SwiftUI, we really recommend it!
- Appcoda: A great tutorial on how to build a Table View with SwiftUI.
- More resources: If you want to learn more about SwiftUI, here’s is great list with all the resources that are currently available!
Hopefully, you enjoyed reading this guide and now know about SwiftUI and how to get started.
Make sure you stay tuned and sign-up to the newsletter.