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

Welcome to Xcode window appears.

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

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

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

Step 4 – Set Project Options

Choose options for the project.

SwiftUI Project - Options Window

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

Step 5 – Choose Project Directory

Choose a directory for the project, and click on Create button.

SwiftUI Project - Select Project Directory

Our HelloWorld project opens with all the boilerplate code.

SwiftUI Hello World Project

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

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

A list of available devices, simulator, etc, appear. Choose one based on the requirement.

Select Simulator to run SwiftUI Project

Run

Now, run this application on the chosen device, by clicking on run button present at above Navigator.

Run SwiftUI Project

Our project starts running on the device.

SwiftUI project run on iPhone 12 simulator

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

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

Assests.xcassets

This contains the list of assets for this project.

Assests.xcassets

info.plist

This file contains information about the properties of this project, like build version, supported orientations, required capabilities, etc.

info.plist

Conclusion

Concluding this SwiftUI Tutorial, we learned how to create an Xcode project with SwiftUI.