With the introduction of SwiftUI comes a new coding paradigm called declarative syntax. Well, I say "new"—it's actually been around for a while; it's just something we've never really used in iOS or macOS development. In this section, we'll take a look at what exactly declarative syntax is and how it compares to the style of syntax we might be used to seeing already.
Getting ready
For this section, you'll need the latest version of Xcode available from the Mac App Store.
How to do it...
- Open Xcode and select File | New | Playground, then select Blank in order to open a new Playground canvas to work from.
- Once open, add in the following syntax:
import PlaygroundSupport
import SwiftUI
The first import statement we've seen before and should be familiar with already. The next is our one for SwiftUI—pretty self-explanatory as to why we need this.
- Now, let's create a view in SwiftUI by adding in the following highlighted...