Mobile development · Beginner · 18 min
How to Build Your First iOS App with SwiftUI
By Padding · Updated 15 Nov 2026
Swift 6.4 · Xcode 27.1
You will create an iOS app in Xcode 27.1 with SwiftUI and Swift 6.4, build a small task list with a text field, toggles and swipe to delete, see it in the live preview and the simulator, and run it on your own iPhone.
On this page
SwiftUI is Apple's framework for building user interfaces on iPhone, iPad, Mac, Apple Watch, Apple TV and Apple Vision Pro. You describe what the screen should show for the current data, in Swift, and SwiftUI updates the screen when the data changes. There is no separate layout file: the code is the interface.
This tutorial builds a task list in Xcode 27.1, which includes Swift 6.4 and the iOS 27.1 SDK, according to Apple's Xcode 27.1 release notes. Xcode 27.1 requires a Mac with macOS Tahoe 26.6 or later. You write the views yourself, see them in a live preview, run them in the iOS Simulator, and then on your iPhone. SwiftUI needs Xcode, so this tutorial is for Mac users. If you are on another system, the first Expo tutorial builds apps for both phone platforms from any computer.
Step 1 · Create the project
Open Xcode. Choose File, New, Project. Pick the iOS tab and the App template, then choose Next. Fill in the options:
- Product Name:
HelloSwiftUI. - Team: leave it empty for now, or choose your Apple Account, which you can add in Xcode's Settings window (in current versions, the Accounts tab; names can differ).
- Organization Identifier: a reverse domain, such as
com.example. Xcode joins it to the product name to make the bundle identifier,com.example.HelloSwiftUI. Use one you own if you will ever publish. - Interface: SwiftUI. Language: Swift.
- Testing System: leave the default.
- Storage: None.
Choose Next, pick a folder, and Create. Xcode makes two Swift files, HelloSwiftUIApp.swift and ContentView.swift, an asset catalogue, and the project.
Step 2 · Read the two starter files
Open HelloSwiftUIApp.swift. It is the entry point:
import SwiftUI
@main
struct HelloSwiftUIApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}@main marks where the app starts. An App has a body that returns one or more scenes, and a WindowGroup is the scene that holds your first screen, ContentView. some Scene is Swift's way of saying "a specific type that conforms to Scene, which I do not need to spell out". Open ContentView.swift. It holds a View, a struct with a body that returns the interface, plus a #Preview block at the bottom that feeds the Xcode canvas.
Step 3 · Open the live preview
Open the canvas with Editor, Canvas, or the shortcut Option+Command+Return. Choose Resume if it asks. The canvas shows the view as an iPhone would, and it redraws as you edit. The #Preview macro at the bottom of the file is what feeds it. Previews need the Mac to compile the view each time, so the first one can take a few seconds.
Step 4 · Write a task list
Replace the whole contents of ContentView.swift with this:
import SwiftUI
struct TodoItem: Identifiable {
let id = UUID()
var title: String
var isDone = false
}
struct ContentView: View {
@State private var tasks = [
TodoItem(title: "Install Xcode"),
TodoItem(title: "Build a SwiftUI app"),
]
@State private var newTitle = ""
var body: some View {
NavigationStack {
List {
Section {
HStack {
TextField("New task", text: $newTitle)
.submitLabel(.done)
.onSubmit(addTask)
Button("Add", action: addTask)
.disabled(newTitle.trimmingCharacters(in: .whitespaces).isEmpty)
}
}
Section("Tasks") {
ForEach($tasks) { $task in
Toggle(task.title, isOn: $task.isDone)
}
.onDelete { offsets in
tasks.remove(atOffsets: offsets)
}
}
}
.navigationTitle("Tasks")
}
}
private func addTask() {
let title = newTitle.trimmingCharacters(in: .whitespaces)
guard !title.isEmpty else { return }
tasks.append(TodoItem(title: title))
newTitle = ""
}
}
#Preview {
ContentView()
}How it works:
TodoItemis a plain struct.Identifiablewith anidlets SwiftUI tell the rows apart, so it can animate adds and removals correctly.@Statemarks data that the view owns. When a@Statevalue changes, SwiftUI runsbodyagain and updates what changed.privateis the convention for state that only this view touches.$newTitleand$task.isDoneare bindings: two-way connections that let theTextFieldand theTogglewrite to your data.ForEach($tasks) { $task in ... }gives each row a binding to its item.List,Section,HStack,ToggleandButtonare built-in views. They look right on each platform without styling. Small modifiers such as.navigationTitle,.disabledand.onDeletechange one thing each and chain with dots.addTasktrims spaces, ignores an empty title, adds the item and clears the field. The Add button is disabled while the field is empty, and pressing Return in the field also adds the task.
Check it worked
The canvas shows a "Tasks" title with two rows that have switches, and an input row above them. In the canvas, you can turn the preview interactive, with the play button under the preview. Type a task and press Add, flip a switch, and swipe a row to the left to delete it.
Step 5 · Run it in the simulator
Choose an iPhone from the device menu at the top of the Xcode window, then press Command+R. Xcode builds the app and opens the iOS Simulator. The first launch of the Simulator can take a few minutes. Try the same things: add a task, tick it, and swipe a row to delete it. Stop the app with Command+. when you are done.
Two things to know. The data is only in memory, so quitting the app clears the changes. To save it, look at SwiftData, Apple's persistence framework, or @AppStorage for small settings. And Xcode's Product, Test command runs the tests in your project, where the template has put an example test target.
Step 6 · Run it on your iPhone
Running on your own device needs a signing identity. A free Apple Account is enough for development on your own devices. Apps signed this way expire after a short period and need to be re-installed from Xcode, and they cannot go on the App Store. Publishing needs the paid Apple Developer Program.
- Connect the iPhone to the Mac with a cable, wake it with its passcode, and tap Trust when it asks.
- On the iPhone, turn on Developer Mode. In current versions of iOS this is in the Settings app, in the Privacy and Security section, under Developer Mode, but menu names can differ between versions. The phone restarts, and you confirm after the restart.
- In Xcode, click the project at the top of the navigator, choose the
HelloSwiftUItarget, open the Signing and Capabilities tab, and choose your Team. Xcode creates a development certificate and a provisioning profile. - Choose your iPhone from the device menu and press Command+R.
- The first time, the phone may say the developer is not trusted. In current versions of iOS this is under Settings, General, then the VPN and Device Management section (names can differ). Choose your Apple Account, and tap Trust.
Troubleshooting
Signing for "HelloSwiftUI" requires a development team: choose a Team in the Signing and Capabilities tab.Failed to register bundle identifier: someone else uses that identifier. Change the Organization Identifier or the Bundle Identifier on the same page.- The canvas says
Cannot preview in this file: look at the diagnostics message in the canvas, and fix the compile error it names. Press Option+Command+P to refresh. - No iPhone in the device menu: wake it with its passcode and trust the Mac. Check Window, Devices and Simulators for its status.
- Xcode says the iOS platform is not installed: open Xcode's Settings window (in current versions, the Components tab; names can differ), and download the iOS simulator runtime.
Step 7 · Clean up
The project holds only what you made. To remove it, quit Xcode and drag the HelloSwiftUI folder to the Bin. The simulator keeps a copy of the installed app. Delete it from the Simulator's home screen the way you would delete an app on a phone.
Next steps
- Build for both phone platforms from one codebase: create your first React Native app with Expo.
- Build with Flutter instead: install Flutter and run your first app.
- Learn how apps reach the stores: build and submit an Expo app with EAS describes the same accounts and steps.
Need this done for you?
Padding does this work for growing companies, from the first diagnosis to a system that keeps working.
Get new tutorials