- 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 code:
import PlaygroundSupport
import SwiftUI
struct MyView: View {
var body: some View {
VStack {
Text("Swift Cookbook")
}
}
}
All SwiftUI views are built in a struct that conforms to the View type—this then houses another struct, which looks a bit like a computed property called body, which in turn conforms to some View. Inside this property—or "function builder", as it's known (which we'll touch on later in this chapter)—we have certain...