In this tutorial, we will learn how to create a project in Xcode with SwiftUI, basic understanding of Xcode application, boilerplate code file created in the project, and run the application on a simulator.
SwiftUI – Create Project in Xcode
Following is a step by step process to create a Project in Xcode with SwiftUI.
Step 1 – Open Xcode
Open Xcode from Dock.
![Mac Dock](https://www.tutorialkart.com/wp-content/uploads/2021/02/swiftui-create-projectin-xcode-0-1024x77.png)
Welcome to Xcode window appears.
![](https://www.tutorialkart.com/wp-content/uploads/2021/02/swiftui-create-projectin-xcode-1.png)
Step 2 – Create a new Xcode project
Under welcome message, there are some options. Click on Create a new Xcode project.
![SwiftUI Project - Create a new Xcode project](https://www.tutorialkart.com/wp-content/uploads/2021/02/swiftui-create-projectin-xcode-2.png)
Step 3 – Choose Template
We have to choose a template for our project, based on the Device Type and Application Type.
![SwiftUI Project - Choose Template](https://www.tutorialkart.com/wp-content/uploads/2021/02/swiftui-create-projectin-xcode-3.png)
In this tutorial, we will create a project with App template for iOS device.
Click on iOS, then under iOS tab, click on App template. Then, click on Next.
![SwiftUI Project - Choose Template](https://www.tutorialkart.com/wp-content/uploads/2021/02/swiftui-create-projectin-xcode-4.png)
Step 4 – Set Project Options
Choose options for the project.
![SwiftUI Project - Options Window](https://www.tutorialkart.com/wp-content/uploads/2021/02/swiftui-create-projectin-xcode-5.png)
Enter a name for this project for Product Name field, and choose SwiftUI for Interface, SwiftUI App for Life Cycle; and click on Next button.
![SwiftUI Project - Set Project Options](https://www.tutorialkart.com/wp-content/uploads/2021/02/swiftui-create-projectin-xcode-6.png)
Step 5 – Choose Project Directory
Choose a directory for the project, and click on Create button.
![SwiftUI Project - Select Project Directory](https://www.tutorialkart.com/wp-content/uploads/2021/02/swiftui-create-projectin-xcode-7.png)
Our HelloWorld project opens with all the boilerplate code.
![SwiftUI Hello World Project](https://www.tutorialkart.com/wp-content/uploads/2021/02/swiftui-create-projectin-xcode-8-1024x684.png)
We have successfully created an iOS application with SwiftUI Interface.
Xcode Project Window
Now, let us dig through the Xcode application, and some of the files in this project.
It has a Navigator, Editor (including Preview), and Options (for any of the selected item in the Navigator or Editor).
![Xcode SwiftUI Project Window](https://www.tutorialkart.com/wp-content/uploads/2021/02/swiftui-create-projectin-xcode-9-1024x684.png)
By default, a device would be selected for the project to run on.
We may change the device on which our built project runs. Like, we may select a Simulator, or download a new Simulator and then select that, etc.
Click on the Device, as shown in the following screenshot, highlighted.
![Device for Running SwiftUI Project](https://www.tutorialkart.com/wp-content/uploads/2021/02/swiftui-create-projectin-xcode-10-1024x684.png)
A list of available devices, simulator, etc, appear. Choose one based on the requirement.
![Select Simulator to run SwiftUI Project](https://www.tutorialkart.com/wp-content/uploads/2021/02/swiftui-create-projectin-xcode-11.png)
Run
Now, run this application on the chosen device, by clicking on run button present at above Navigator.
![Run SwiftUI Project](https://www.tutorialkart.com/wp-content/uploads/2021/02/swiftui-create-projectin-xcode-17.png)
Our project starts running on the device.
![SwiftUI project run on iPhone 12 simulator](https://www.tutorialkart.com/wp-content/uploads/2021/02/swiftui-create-projectin-xcode-12-546x1024.png)
Project Files
Let us walkthrough some of the files that are created for this project.
HelloWorldApp.swift – [ProjectName]App.swift
This swift file has a struct with main attribute @main
. This is the entry point for our project, when it is run.
![HelloWorldApp.swift](https://www.tutorialkart.com/wp-content/uploads/2021/02/swiftui-create-projectin-xcode-13-1024x647.png)
ContentView.swift
This file, contains the View, which is displayed in the UI. This contains the “Hello, world!” text displayed in the UI.
![ContentView.swift](https://www.tutorialkart.com/wp-content/uploads/2021/02/swiftui-create-projectin-xcode-14-1024x647.png)
Assests.xcassets
This contains the list of assets for this project.
![Assests.xcassets](https://www.tutorialkart.com/wp-content/uploads/2021/02/swiftui-create-projectin-xcode-15-1024x647.png)
info.plist
This file contains information about the properties of this project, like build version, supported orientations, required capabilities, etc.
![info.plist](https://www.tutorialkart.com/wp-content/uploads/2021/02/swiftui-create-projectin-xcode-16-1024x540.png)
Conclusion
Concluding this SwiftUI Tutorial, we learned how to create an Xcode project with SwiftUI.