Previews and the simulator
Now, for the sake of simplicity, we will start again by creating a simple single-view project.
You can create a new project from the Xcode menu: File | New | Project.
You will see that Xcode will automatically create a simple project and create a view struct and a preview struct inside the ContentView.swift
file.
The first struct inside this file describes a simple SwiftUI view (Text
) and the second struct is used to pre-render it so that you can have an idea of the finished result without the need to launch the simulator.
You can have multiple previews, even for different devices simultaneously, but that depends heavily on the memory available on your system and has been somewhat error prone in the past.
You can give each preview a name, by using the previewDisplayName
modifier on the content view in the preview, for example, name the currently rendered device
iPod.
You can also change the desired rendered device in code using the previewDevice...