Challenge - 5 Problems
First iOS App Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What will this SwiftUI code display?
Consider this SwiftUI view code. What text will appear on the screen when the app runs?
iOS Swift
import SwiftUI struct ContentView: View { var body: some View { Text("Welcome to my first app!") .font(.title) .foregroundColor(.blue) } }
Attempts:
2 left
💡 Hint
Look at the modifiers .font(.title) and .foregroundColor(.blue).
✗ Incorrect
The Text view shows the string with a title font size and blue color as specified.
intermediate
2:00remaining
What happens when this button is tapped?
This SwiftUI code shows a button inside a NavigationView. What happens when the user taps the button?
iOS Swift
import SwiftUI struct ContentView: View { var body: some View { NavigationView { NavigationLink("Go to Details", destination: Text("Details Screen")) .navigationTitle("Home") } } }
Attempts:
2 left
💡 Hint
NavigationLink creates a tappable link to a destination view.
✗ Incorrect
Tapping the NavigationLink navigates to the destination view showing 'Details Screen'.
❓ lifecycle
advanced2:00remaining
When is the body property of a SwiftUI View recomputed?
Given this SwiftUI view with a @State variable, when does the body property get recomputed?
iOS Swift
import SwiftUI struct ContentView: View { @State private var count = 0 var body: some View { VStack { Text("Count: \(count)") Button("Increment") { count += 1 } } } }
Attempts:
2 left
💡 Hint
Think about how @State triggers UI updates.
✗ Incorrect
Changing a @State variable causes SwiftUI to recompute the body to reflect UI changes.
📝 Syntax
advanced2:00remaining
What error does this SwiftUI code produce?
Examine this SwiftUI code snippet. What error will it cause when compiling?
iOS Swift
import SwiftUI struct ContentView: View { var body: some View { VStack { Text("Hello") Button("Tap me") { count += 1 } } } }
Attempts:
2 left
💡 Hint
Check the Button syntax and its action closure.
✗ Incorrect
Button requires an action closure after the label; missing closure causes syntax error.
🔧 Debug
expert3:00remaining
Why does this SwiftUI view not update the text when the button is tapped?
This code intends to update the displayed text when the button is tapped, but it does not. Why?
iOS Swift
import SwiftUI struct ContentView: View { var count = 0 var body: some View { VStack { Text("Count: \(count)") Button("Increment") { count += 1 } } } }
Attempts:
2 left
💡 Hint
Think about how SwiftUI tracks changes to update the UI.
✗ Incorrect
Only @State properties trigger UI updates when changed; regular vars do not.