Building & Running SwiftUI Apps in Xcode
Written by Team Kodeco
When you create a new SwiftUI project in Xcode, you start with a simple SwiftUI view. For instance, Xcode might generate a ContentView
like the one in our “Hello World” example:
struct ContentView: View {
var body: some View {
Text("Hello, world!")
.padding()
}
}
To build and run this app, click the Play button in Xcode’s toolbar or press Command-R. This compiles the code and launches the app in the simulator or a connected iOS device, selectable from the drop-down next to the Play button.
Your preview should look like this:
Upon a successful build, you should see “Hello, world!” displayed on the device or simulator screen:
If you encounter build errors or warnings, Xcode’s debug console provides detailed information. To stop the app, press Command-. or click the Stop button in the toolbar.
This simple process of building and running your app is the first step towards more advanced development tasks with SwiftUI.