Chapter 1 Exercises — Hello, World
These exercises go with Chapter 1. Do the independent challenge on a Git branch, so the guided project stays identical to the reference.
Independent Challenge — Make the screen yours
Goal
Change the starting screen so it shows an icon and a line of text that are your own, not the course's.
Requirements
- The screen still shows exactly one icon and one line of text, stacked vertically.
- The text is your name, or a name you choose.
- The icon is an SF Symbol other than
dice. Search for a name in the SF Symbols app. - The app builds with no errors and no warnings.
Acceptance criteria
- You can run the app with ⌘R and see your icon and your name on the screen.
ContentView.swiftcontains your text and your symbol name, and nothing else in the file changes except what is needed.- You made the change on a branch named
challenge-01, and you switched back tomainafterward.
Setup
First commit and tag the guided work using the workbook's Development Checkpoint. Confirm git status --short prints nothing, then create the branch:
git switch -c challenge-01
When you finish:
Uncommitted edits can follow you across branches. Save them before switching; if nothing changed, skip add and commit. The status command should print nothing:
git add -A
git commit -m "Challenge 01: Save practice work"
git status --short
git switch main
Hint 1
Only one line of ContentView.swift contains the words on the screen, and only one line contains the icon name. You do not need to add or remove any views.
Hint 2
Find the line that starts with Text(. Its argument is a string in quotation marks. Find the line that starts with Image(systemName:. Its argument is also a string in quotation marks, and it must match a symbol name exactly.
Hint 3
Replace the string inside the Image(systemName: argument with a symbol name you have verified in the SF Symbols app. Replace the string inside Text( with your name. Do not change the indentation or the .imageScale and .foregroundStyle lines below the Image line; they still apply to the new icon.
Extra practice
Exercise 1 — Predict the layout
Without running the app, predict what the screen shows for this body. Then run it and compare.
var body: some View {
VStack {
Text("Dice")
Image(systemName: "dice")
}
}
Questions:
- Which appears first, the text or the icon?
- Would the screen be different if the
.padding()modifier were removed from the original template? (Answer later in Chapter 3.)
Exercise 2 — Spot the bug
A student's ContentView.swift does not build. The error message appears on the line that starts Text(. The line reads:
Text("Dice Foundry)
Find the problem without running the build. Then explain why Xcode reports the error on this line, and suggest one way to make a missing quotation mark easier to spot.
Exercise 3 — Find the entry point
Without opening any file other than DiceFoundryApp.swift, answer these questions:
- What is the name of the type that iOS creates first when your app launches?
- What does the
WindowGroupcontain? - Where would you add a second
Textview so that it appears below the dice text? Name the file and the place in it.
Exercise 4 — Change the deployment target and observe
Change Minimum Deployments to iOS 16.0, then open ContentView.swift. Does Xcode show any new errors? Change it back to 17.0. Write one sentence explaining why you think Xcode behaves as it does.
Do not leave the deployment target at 16.0 for the rest of the course.