Chapter 1 — Hello, World
Welcome. This chapter is where you first see an iPhone app run, and it is deliberately small. You will create a project in Xcode, find the line of code that puts the words "Hello, World!" on the screen, change those words, run the app in the iPhone Simulator, and then turn the same screen into the first version of Dice Foundry. Along the way you learn the handful of Xcode controls you will use in every chapter: the navigator, the editor, the Run button, the preview canvas and the Simulator.
Nothing in this chapter requires any prior programming experience. You are not expected to understand Swift yet. Chapter 2 teaches the Swift language one idea at a time, and Chapter 3 begins building the real interface. Here, your only goal is to make a program run and to understand what each visible part of the program corresponds to.
You need a Mac that can run Xcode 27, Xcode itself installed from the Mac App Store, and about 20 GB of free disk space for Xcode and its simulators. An Apple ID is not required to run apps in the Simulator. It is required only if you later want to put an app on a real iPhone. Physical-device installation is outside this course's verified scope and is described only briefly in the Troubleshooting section.
Learning Objectives
By the end of this chapter you will be able to:
- Open Xcode and create a new iOS App project using the SwiftUI interface.
- Identify the main Xcode areas: the navigator, the editor, the toolbar, the debug area and the canvas.
- Run an app in the iPhone Simulator with ⌘R, and stop it with ⌘.
- Explain what the preview canvas is, and how it differs from running the app.
- Find the file that defines the text on the screen, and change it.
- Explain, in plain English, what
import SwiftUI,struct,var bodyandTextdo in a first program. - Change the minimum iOS version and the name that appears under the app icon.
- Create a Git repository for your project and save a checkpoint with a commit and a tag.
Concept Explanation
What an iPhone app is, in one paragraph
An iPhone app is a folder of compiled code and resources that the iOS operating system launches when you tap its icon. The system gives the app a window, sends it touch events, and asks it to draw what should be on the screen. Your job as the developer is to write the code that answers those requests: "what should the screen contain right now?" and "what should happen when the user taps this?"
Xcode is Apple's development environment. It is the application where you write the code, organize the files, build the app (compile it into a runnable form), run it in a simulator, and inspect what it is doing. Everything in this course is done in Xcode.
If you have ever run a Makefile, a CI pipeline, or a terraform plan followed by apply, you already know the shape of the workflow. Xcode is the place where you edit the source, press a button to build (compile and link), and press another to run it somewhere. The Simulator is like a disposable virtual machine that runs the iOS operating system, so you can test without touching a real device. The debug area is the console where the app's own log output appears.
Projects, targets and files
When you create a new app, Xcode creates a project. A project is a container for everything the app needs: source files, images, settings and the instructions for building it. Inside the project, a target describes one product to build. This course uses one target, the app itself. Later, Chapter 12 adds a second target for automated tests.
Files live in the navigator, the panel on the left side of the Xcode window. Some items in the navigator are folders in disk, and some are groups that exist only inside Xcode. Chapter 10 explains that difference when we organize the code into folders.
Clicking the blue project icon at the top of the navigator opens the project editor. Settings there apply to the whole project. Settings under the target name apply to the product that is built. In this chapter you change two target settings: the minimum iOS version and the display name.
SwiftUI and the first file you will read
Xcode's template for a new iPhone app creates two Swift files that matter in this chapter:
DiceFoundryApp.swifttells iOS how to start your app.ContentView.swiftdescribes the first screen.
You will read both files in detail in the Syntax Breakdown and in Reading This Like a Developer. For now, the important point is that the screen is defined by code you can edit, and that editing it changes what you see the next time the app runs or the preview refreshes.
What is on disk, and what each item is
After Step 2 you will see a few items in the navigator and a few more in Finder. It helps to know what each one is before you start editing, so that nothing in the project looks mysterious.
DiceFoundry.xcodeprojis the project file, visible in Finder in the folder you chose. It records the list of files, the build settings and the targets. You open it (or double-click it) to open the project in Xcode. Xcode edits it for you; you do not edit it by hand.- The inner
DiceFoundryfolder holds your source files and resources. In this chapter it containsDiceFoundryApp.swift,ContentView.swiftandAssets.xcassets. DiceFoundryApp.swiftis the entry point. iOS finds the@mainmarker in this file and starts the app from there. You read it in Reading This Like a Developer, and you change nothing in it in this chapter.ContentView.swiftis the first screen. It is the only source file you edit in this chapter.Assets.xcassetsis the asset catalog, a folder of images and colors that Xcode manages. The template includes an entry namedAccentColor, which is the tint that.foregroundStyle(.tint)uses. Some Xcode versions also list anAppIconentry for the app's icon. Chapter 11 fills that icon in; if your list has noAppIconentry, Chapter 11 shows how to add one. You do not need to open this folder yet.- The hidden
.gitfolder exists because you left Create Git repository on my Mac checked. It stores the history that the Development Checkpoint uses. Finder hides it by default; Terminal shows it withls -a.
If you think of the source files as your application's content, DiceFoundry.xcodeproj is the manifest that says which files belong to the build and how to build them. Moving or deleting a file in Finder without telling Xcode leaves the manifest pointing at something that is not there, the same way a stale entry in a deployment manifest does. Add, move and delete files from inside Xcode's navigator whenever you can.
What the preview canvas is
The canvas is a panel that shows a live rendering of one view. It runs your code in a small, fast environment to draw the view you pick. It is an excellent tool for iterating on layout, but it is not a full app. Some things, such as the app's launch sequence, appear only when you run the app in the Simulator.
When you change code, the canvas updates after a short delay. If it stops updating, press ⌥⌘P (Resume) or the Resume button in the canvas. If it shows an error, read the message: it often tells you the line that failed.
What the Simulator is
The Simulator is a program that runs iOS on your Mac. It lets you choose an iPhone model and iOS version, install your app and tap it. The app does not run on your Mac's processor directly in the same way as a Mac app; it runs as iOS code inside the Simulator. Results are very close to a real phone, but not identical. Touch feel, battery behavior, sensors and performance differ, and the Simulator cannot test vibration (haptics). Keep these limits in mind as we go.
The difference between Run and Preview
| Preview canvas | Run in Simulator | |
|---|---|---|
| Starts from | The #Preview block at the bottom of a file |
The @main app declaration |
| Shows | One view, on its own | The whole app, from its launch sequence |
| Speed | Fast; updates as you edit | Slower; builds and installs first |
| Taps and navigation | Limited in some cases | Full behavior |
| Best for | Layout details | Checking behavior and the whole flow |
Use both. The preview helps you iterate; the Simulator confirms the real app.
Syntax Breakdown
The first program you will run contains only a few pieces of Swift. Here is the complete ContentView.swift that the Xcode template creates on a current Xcode version. The exact wording may differ slightly on your Xcode, and the default image may be a globe. The important structure is the same:
import SwiftUI
struct ContentView: View {
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Hello, world!")
}
.padding()
}
}
#Preview {
ContentView()
}
Each token has a job. Learn the vocabulary now; Chapter 2 explains each piece in full, and Chapter 3 explains the layout pieces.
| Token | Meaning |
|---|---|
import SwiftUI |
Makes SwiftUI's names (such as View, Text and Image) available in this file. Think of it as a library include. |
struct ContentView |
Declares a new type named ContentView. A struct groups related code. Your screen is a type of its own. |
: View |
Says that ContentView promises to meet the requirements of the View protocol. The main requirement is a body property. |
var body: some View |
The property that describes what the view looks like. some View means "some kind of view, which the compiler works out." |
VStack { … } |
A layout container that places its children from top to bottom. |
Image(systemName: "globe") |
An icon from Apple's built-in symbol library. The name is a string; "globe" is one of thousands of names. |
Text("Hello, world!") |
A view that shows the given string of characters. |
.padding() |
A modifier that adds space around the stack. Modifiers are chained with dots. |
#Preview { … } |
A block that tells the canvas which view to display. It is not part of the running app. |
Guided Implementation
Work through these steps in order. Each step shows the file, the place in the file, what changes and what you should see. Use ⌘R to run the app at the checkpoints marked "Run."
Step 1 — Check your Xcode version
Open Xcode from the Applications folder or from Spotlight (⌘Space, type "Xcode"). Choose Xcode → Settings (⌘,) and then the Platforms or Components section, depending on your version. Confirm that an iOS Simulator runtime is installed. If none is installed, download one from the same place. Close Settings.
The course was verified on Xcode 27.2 (build 27B52). Menu names and template code can change between versions. If a name in these steps is slightly different on your Xcode, look for the closest match. The steps are written so that the purpose of each action is clear even when the wording differs.
Step 2 — Create the project
File: none (new project) · Where: Xcode menu bar · Action: Create
- Choose File → New → Project…
- At the top of the template chooser, select iOS. Under Application, select App. Click Next.
- Fill in the options:
- Product Name:
DiceFoundry. This becomes the name of the project and the main source folder. Do not put spaces in it. - Team: choose None unless you have an Apple developer account and want to sign the app for a device (see Optional Device Lesson D1). The Simulator does not need a team. - Organization Identifier: use a reverse-domain name you control, for examplecom.yourname. Xcode combines this with the product name to form the Bundle Identifier, a unique ID for the app. The course's examples usecom.blackwellfoundry; use your own value. - Interface: SwiftUI. - Language: Swift. - Storage: None. Chapter 9 adds persistence by hand; the template's storage options would add code you are not ready to read. - Include Tests: leave this unchecked. Chapter 12 adds a test target step by step. - Click Next. Choose a folder on your disk (for example
Documents/DiceFoundryCourse). Leave Create Git repository on my Mac checked. We use Git in the Development Checkpoint. Click Create.
Xcode opens the project. You should see the project in the navigator on the left, with a folder named DiceFoundry containing DiceFoundryApp.swift, ContentView.swift and Assets.xcassets.
Xcode stores paths to your files. If you later move the project folder in Finder, Xcode will usually find it again, but Git and the Development Checkpoint commands in this chapter assume a stable location. Choose a folder once and keep it.
Step 3 — Run the template app
File: none · Where: the toolbar at the top of the Xcode window · Action: Run
- In the toolbar, the device menu shows a Simulator name such as iPhone 17 Pro. If you have several simulators, pick an iPhone model. Any recent iPhone works.
- Press ⌘R or click the ▶ button.
- Wait while Xcode builds the app and starts the Simulator. The first build takes longer than later builds.
You should see a simulated iPhone with the template screen: a globe icon and the words "Hello, world!" The app is running. The Xcode window now shows the debug area at the bottom, and the stop button in the toolbar is active.
Press ⌘. (command and period) to stop the app. The Simulator window may remain open; that is normal.
⌘B builds the app without running it, which is useful when you only want to check for errors. ⌘R builds and runs it. If the build fails, Xcode shows an error in the navigator and in the editor, and the app does not start.
Step 4 — Find the text in the code
File: ContentView.swift · Where: navigator, in the DiceFoundry folder · Action: Open
Click ContentView.swift in the navigator. The editor shows the code you read in the Syntax Breakdown. Find the line that contains Text("Hello, world!").
Notice that the text you see in the Simulator is exactly what appears inside the quotation marks. Changing the code changes the screen. That is the basic relationship you will use for the rest of the course.
Now look at the canvas on the right side of the editor. If you do not see it, press ⌥⌘↩ (option, command, return) to show it. The canvas shows the same text inside the #Preview block. If it does not appear, press ⌥⌘P to resume the preview.
Step 5 — Change the words on the screen
File: ContentView.swift · Where: inside ContentView's body, the Text line · Action: Replace
Replace the line that reads Text("Hello, world!") with this line. Keep the indentation: twelve spaces at the start of the line, because it sits inside VStack, which sits inside body.
Text("Hello, World!")
Note: this line is an intermediate edit. Step 8 replaces the whole VStack with the final Dice Foundry layout, so you will not keep this exact text.
What it does: Text shows the characters between the quotation marks. What it does not do: anything else. The words change because the view's description changed, not because you told the screen to update.
Check the canvas. It should now show "Hello, World!" after a short delay. Press ⌘R to see the same change in the Simulator. Stop the app with ⌘. when you are done.
In the template, Image(systemName: "globe") is followed by Text("Hello, world!") inside a VStack. If you replaced the Text line with Text("Hi") and deleted the Image line as well, what would the screen show, and would the words be above or below the icon? Write your answer down before you check the canvas.
(Answers appear in Prediction Answers at the end of this chapter.)
Step 6 — Set the minimum iOS version to 17.0
File: the project (blue icon at top of the navigator) · Where: select the DiceFoundry target, then the General tab, then Minimum Deployments · Action: Replace
- Click the blue DiceFoundry project icon at the top of the navigator.
- In the list under TARGETS, select DiceFoundry.
- Select the General tab.
- Find Minimum Deployments and set the iOS value to 17.0. Use the menu or type the number.
The deployment target is the oldest iOS version your app will run on. New projects default to the newest iOS. Setting it to 17.0 lets the app run on iPhones that cannot update to the newest iOS, and every feature this course uses is available on iOS 17.0 and later. Choosing a higher number than the course needs narrows the range of devices that can run your app. Choosing a lower number than the course needs causes compile errors later, because some APIs (such as @Observable in Chapter 13) appear only in iOS 17.
Changing the deployment target now means every later step is verified against the same minimum. If you forget, the course's later code may compile against a newer iOS than the one you test on. Change it once, now, and do not change it again.
Step 7 — Set the display name
File: the project · Where: target DiceFoundry → General → Identity → Display Name · Action: Replace
In the same General tab, find the Identity section. Set Display Name to Dice Foundry (with a space). The Bundle Identifier and the project name stay as they are.
The display name is the text that appears under the app icon on the Home Screen. The product name, DiceFoundry, is the internal name used for the project and the folder. They can differ, and in this course they do: the code uses DiceFoundry, and the Home Screen shows Dice Foundry.
Step 8 — Replace the template's view with the Dice Foundry starting screen
File: ContentView.swift · Where: inside struct ContentView, replace everything from var body: some View { down to its matching closing brace } · Action: Replace
Select the whole body and replace it with the code below. The lines in this block match the reference file for this checkpoint exactly. Notice that the body now shows a dice icon and the words "Dice Foundry". The icon name dice is an SF Symbol available in the current symbol library.
var body: some View {
VStack {
Image(systemName: "dice")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Dice Foundry")
}
.padding()
}
What it does: the VStack stacks two views, a large dice icon tinted with the app's accent color, and a line of text. .padding() adds space around the stack. The rest of the file (the import, the struct line, the #Preview) is unchanged.
Why it is written this way: this is the same VStack you read in the template, with two different views inside. Choosing a stack keeps everything you need for a first screen in one readable block. Chapter 3 explains each modifier in detail.
After this edit, check the canvas. You should see the dice icon above the words "Dice Foundry."
Image(systemName: "dice") needs an SF Symbol named dice. If the canvas shows a question mark in a box, check the spelling and capitalization of dice exactly. Symbol names are case-sensitive.
Step 9 — Run the app
File: none · Where: toolbar · Action: Run
Press ⌘R. In the Simulator, the app opens to the dice icon and the text "Dice Foundry," centered on the screen. The icon is tinted with the accent color of the app.
Stop the app with ⌘. before you continue.
Step 10 — Confirm what you built
Look at the navigator. Your project should now contain the same two Swift files as the reference, along with Assets.xcassets. The only file whose code you changed is ContentView.swift.
To confirm the same code appears in the reference, open the reference file Reference-Checkpoints/Checkpoint-01-Getting-Started/DiceFoundry/ContentView.swift in any text editor and compare its body property with the one you just wrote. They should match, except for indentation differences your editor may show.
Expected Results
When the app runs correctly at the end of this chapter, the Simulator shows a plain white or dark screen (depending on the Simulator's appearance) with a centered dice icon above the words "Dice Foundry." The icon is tinted with the default accent color, which is blue on the template; Chapter 11 changes the color scheme.
The layout is vertically centered because VStack is centered by default and the surrounding screen supplies the space. You should see no errors in the Xcode issue navigator (the warning and error icons in the navigator) and no runtime messages in the debug area other than routine system logs.
Illustrative mockup — not a screenshot:
+------------------------------+
| |
| |
| (dice) |
| |
| Dice Foundry |
| |
| |
+------------------------------+
The Simulator's actual rendering will differ in size, color and exact spacing.

Figure: the app on first launch in light appearance, as it looks in the iOS Simulator. Your device may differ slightly in size and spacing.
Reading This Like a Developer
Reading code means tracing what runs, in what order, and what depends on what. Here is the trace for the app you just ran.
Where execution begins. When you press ⌘R, iOS launches the app. The launch starts at the code marked @main. In DiceFoundryApp.swift, that is the struct declared as DiceFoundryApp. Its body says that the app's single scene is a window containing ContentView().
import SwiftUI
@main
struct DiceFoundryApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
The chain of views. WindowGroup creates the window. Inside it, SwiftUI asks for the body of ContentView. That body describes a VStack with two children and padding. SwiftUI then asks each child for its own description: the image and the text.
Where the data comes from. There is no data yet. Every string and symbol name in this chapter is a literal written directly in the code. The screen is a pure function of the code: if the code is the same, the screen is the same.
Where the screen is drawn. You never draw anything. SwiftUI reads the descriptions and turns them into what you see. When you change the code and run again, SwiftUI produces a new description from the new code.
Business logic versus presentation. This chapter has no business logic. Everything in ContentView is presentation: what the screen looks like. Later chapters add logic (rolling dice, saving history). Keeping presentation and logic apart is one of the main reasons to read the code in this way.
Error handling. Nothing in this chapter can fail at runtime, so there is no error handling. The errors you can encounter are compile-time errors, which Xcode reports before the app runs.
Troubleshooting
The build fails with an error in ContentView.swift. Read the first error in the issue navigator (click the warning triangle icon in the navigator, or press ⌘5). It names the line and the problem. The most common cause in this chapter is a missing or extra brace, or a quotation mark that was not closed. Compare your code line by line with the Guided Implementation. If you cannot find the cause, press ⌘Z to undo your last edit until the template returns, and try Step 8 again.
The message says something similar to "Cannot find 'Dice' in scope" or "Cannot find type 'ContentView'". A name in the file is misspelled, or the file is not part of the target. Click the file in the navigator and check the File Inspector (⌥⌘1) under Target Membership; the DiceFoundry box should be checked.
The canvas says something similar to "Failed to build" or shows a red error box. Click the error in the editor, or open the issue navigator. Fix the error and press ⌥⌘P to resume the preview.
The Simulator does not start, or Xcode says something similar to "Unable to boot the simulator." Open Xcode → Settings → Platforms (or Components), and confirm that the iOS runtime is installed. If it is, quit Simulator from its menu, restart Xcode, and try again. If it still fails, restart your Mac.
The icon shows a question mark. The symbol name is not recognized. Check for dice in lowercase, with no spaces. You can search for the name in the SF Symbols app, which Apple provides with Xcode.
The canvas is blank or missing. Press ⌥⌘↩ to show it, then ⌥⌘P to resume. Confirm that ContentView.swift is the file open in the editor, because the canvas shows the #Preview block of the file you are editing. If the file has no #Preview block, there is nothing to draw.
Terminal says something similar to "fatal: not a git repository". You are not in the project folder, or you cleared Create Git repository on my Mac in Step 2. Check where you are with pwd and list the folder with ls -a; the folder that contains DiceFoundry.xcodeproj should also contain a hidden .git folder. If it does not, change into the right folder with cd. If the repository was never created, run git init there once, then repeat the Development Checkpoint commands.
git switch main says something similar to "invalid reference: main". Your repository's first branch may have a different name. Run git branch to see the branches that exist and the one marked with an asterisk, and switch to that name instead.
Xcode shows a signing error such as "Signing for DiceFoundry requires a development team". This appears when you build for a real device, not for the Simulator. Choose an iPhone Simulator in the toolbar's device menu and build again. If the message still appears for a Simulator, check that Team is None in the target's Signing & Capabilities tab. To install on your own iPhone, see Optional Device Lesson D1.
The app shows the old text after you changed the code. You may have run the old build. Stop the app with ⌘., press ⌘R again, and wait for the build to finish. If the canvas is stale, press ⌥⌘P.
Running on a real iPhone. This course's verified path is the Simulator. Optional Device Lesson D1 covers installing on your own iPhone, using Apple's current documentation. The course author has not tested those steps on hardware.
Knowledge Check
- Which Xcode file defines the text and icon on the first screen? Where in that file does the screen's description begin?
- What is the difference between building (⌘B) and running (⌘R)?
- Why does the Dice Foundry Home Screen name differ from the project's product name?
- In your own words, what does the
#Previewblock do, and does it run when you press ⌘R? - Why did we change the minimum iOS version to 17.0 in this chapter, and what would happen if the course's later code used an API newer than your deployment target?
Independent Challenge
Before creating a challenge branch, run this chapter's Development Checkpoint on main to commit and tag the guided work. Confirm git status --short prints nothing. After the challenge, commit your practice edits on the challenge branch before switching back to main; uncommitted edits can follow you across branches. If no files changed, no extra commit is needed. The guided checkpoint is already saved, so skip its commit and tag commands when you reach that section again.
Change the app so that it shows your own name instead of "Dice Foundry," and changes the icon to a different SF Symbol that you find in the SF Symbols app. Do this on a Git branch so the guided project stays identical to the reference.
Requirements:
- The screen shows an icon and a line of text.
- The text is your name, or a name you choose.
- The icon is a different SF Symbol from
dice. - The app builds with no errors and no warnings.
Do this on a branch:
git switch -c challenge-01
When you are finished, return to the main line:
git add -A
git commit -m "Challenge 01: Save practice work"
git status --short
git switch main
Progressive hints are in ch01-exercises.md. The solution is in ch01-answers.md.
Chapter Completion Checklist
- I created a project named
DiceFoundry, using the SwiftUI interface and the Swift language, with no test target. - I ran the unchanged template with ⌘R and stopped it with ⌘.
- I changed the text to "Hello, World!" and saw it update in the canvas.
- I set Minimum Deployments to iOS 17.0.
- I set the Display Name to "Dice Foundry."
- I replaced the body of
ContentViewwith the Dice Foundry starting layout. - I ran the app and saw the dice icon with "Dice Foundry."
- I can point to the
@maindeclaration and explain where the app starts. - I created a Git repository and saved the chapter checkpoint.
Development Checkpoint
Save your work as a Git commit, and mark it with a tag so you can return to this exact state. In Xcode, choose Source Control → Commit… (or Integrate → Commit on some versions), type the message Chapter 1: Hello, World, and commit. Or, in Terminal, from the project folder:
cd ~/Documents/DiceFoundryCourse/DiceFoundry
git add -A
git commit -m "Chapter 1: Hello, World"
git tag chapter-01
Adjust the path to where you saved your project. The cd command changes into the folder that contains the .xcodeproj file.
To compare your project with the reference for this chapter, run this from the folder that contains both your project and the course's Reference-Checkpoints folder. Replace the paths with your own:
diff -r Reference-Checkpoints/Checkpoint-01-Getting-Started/DiceFoundry ~/Documents/DiceFoundryCourse/DiceFoundry/DiceFoundry
The only differences you should see are in files Xcode generates (such as the project file and the assets folder) and whitespace. The two .swift files should match the reference, except for any indentation your editor adds.
Prediction Answers
Predict before you run, Step 5. If you replace Text("Hello, world!") with Text("Hi") and delete Image(systemName: "globe"), the VStack contains only one child: a text view that says "Hi." The screen shows the word "Hi" centered on the screen, with no icon above it. Because the text is the only child, it is not "above" or "below" anything. If you kept the icon and changed only the text, the words would appear below the icon, because VStack places its children from top to bottom in the order they are written.