Chapter 1 Answers — Hello, World
Knowledge Check answers
1. Which Xcode file defines the text and icon on the first screen? Where does the screen's description begin?
ContentView.swift defines the first screen. The description begins at var body: some View {, which sits inside struct ContentView: View.
2. What is the difference between building (⌘B) and running (⌘R)?
Building compiles the code and reports any errors, but does not start the app. Running builds the app (if needed), installs it in the Simulator and starts it. Use ⌘B when you only want to check that the code is valid; use ⌘R when you want to see the app behave.
3. Why does the Dice Foundry Home Screen name differ from the project's product name?
The product name (DiceFoundry) is the internal name for the project and its folders, and it cannot contain spaces in the way the course uses it. The display name is the text iOS shows under the icon, and that can include a space. You set the display name in the target's General tab, Identity section.
4. What does the #Preview block do, and does it run when you press ⌘R?
The #Preview block tells the canvas which view to draw next to the code. It is for development only; it is not part of the running app. Pressing ⌘R runs the app's launch sequence, which starts at @main in DiceFoundryApp.swift, and does not read the #Preview block.
5. Why did we change the minimum iOS version to 17.0, and what would happen if later code used an API newer than the deployment target?
Setting 17.0 lets the app run on iPhones that cannot update to the newest iOS, and every feature the course uses is available on iOS 17.0. If later code used an API introduced after your deployment target, the compiler reports an error on that line, usually saying the API is only available in a newer iOS version. The fix is either to raise the deployment target, which narrows the devices that can run the app, or to avoid the API.
Independent Challenge — Solution
Where the change goes
File: ContentView.swift. Location: inside body, in the VStack. Two lines change: the Image(systemName:) line and the Text(...) line.
The solution
The following is a complete valid ContentView.swift for the challenge, using the name "Alex Rivera" and the star.fill symbol. Replace Alex Rivera with your own name, and use any SF Symbol you have checked in the SF Symbols app.
//
// ContentView.swift
// DiceFoundry
//
import SwiftUI
struct ContentView: View {
var body: some View {
VStack {
Image(systemName: "star.fill")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Alex Rivera")
}
.padding()
}
}
#Preview {
ContentView()
}
Why it works
Image(systemName:) takes a string that names a symbol in Apple's symbol library. Changing that string changes which symbol appears; the modifiers on the next lines still apply because they are chained to the Image view. Text(...) shows whatever string you pass. Nothing else in the layout depends on the old text or symbol, so you change only those two lines.
Alternatives
You can use any symbol name that exists in the SF Symbols app, such as die.face.5 or heart.fill. You could also change .foregroundStyle(.tint) to a fixed color such as .foregroundStyle(.orange), but that is a separate change beyond the challenge.
Verified: compiles with 0 errors and 0 warnings (Xcode 27.2, iOS 17.0 target). The verification run used the Checkpoint 01 project with the two lines above changed; see the challenge-solutions folder.
Exercise answers
Exercise 1 — Predict the layout. The text "Dice" appears above the dice icon, because VStack places children in the order they are written. Without .padding(), the stack has no extra space around it, so it sits closer to the edges of the screen. Chapter 3 explains padding in detail.
Exercise 2 — Spot the bug. The string opened with a quotation mark after Dice Foundry is never closed. The line should read Text("Dice Foundry"). Xcode reports the error on the Text( line because that is where the string literal begins and the parser can no longer read the rest of the line correctly. A good habit is to read each line aloud and confirm that every opening quotation mark has a closing one before you build.
Exercise 3 — Find the entry point.
- The type is
DiceFoundryApp, the struct marked@main. iOS creates it first. - The
WindowGroupcontains the views that the app shows in its window. Here it containsContentView(). - Add the
Textinside theVStackinContentView.swift'sbody, after the existingText("Dice Foundry")line. TheVStackplaces its children from top to bottom, so the new text appears below the first one. Adding code toDiceFoundryApp.swiftis not the right place, because that file only starts the app and names the first screen.
Exercise 4 — Change the deployment target and observe. Xcode may show no errors in ContentView.swift, because the template uses only APIs available in iOS 16. Xcode may still show warnings about features that require a newer iOS. The course's later code uses APIs introduced in iOS 17, so the deployment target must be 17.0 for those chapters to compile. Set it back to 17.0 before continuing.