Challenge - 5 Problems
Modifier Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What color will the text be?
Consider this SwiftUI code that chains modifiers on a Text view. What color will the text appear as on screen?
iOS Swift
Text("Hello World")
.foregroundColor(.red)
.foregroundColor(.blue)Attempts:
2 left
💡 Hint
Think about the order of modifiers and which one applies last.
✗ Incorrect
In SwiftUI, modifiers are applied in order. The last foregroundColor(.blue) overrides the previous .red, so the text color is blue.
📝 Syntax
intermediate2:00remaining
Which modifier chain compiles without error?
Which of these SwiftUI modifier chains is syntactically correct?
Attempts:
2 left
💡 Hint
Check if each modifier is called as a function with parentheses.
✗ Incorrect
Modifiers like padding(), background(), and font() require parentheses. Option A uses them correctly. Options A, B, and C have syntax errors.
❓ lifecycle
advanced2:00remaining
What happens if you chain .onAppear twice?
Given this SwiftUI code, what will happen when the view appears?
iOS Swift
Text("Welcome") .onAppear { print("First") } .onAppear { print("Second") }
Attempts:
2 left
💡 Hint
Think about whether modifiers replace or add behavior.
✗ Incorrect
Each .onAppear adds a separate action. Both closures run when the view appears, so both messages print.
advanced
2:00remaining
Which modifier chain correctly adds a navigation title and a button?
Which SwiftUI modifier chain correctly adds a navigation title and a trailing button to a view?
Attempts:
2 left
💡 Hint
Check the correct modifier names and their order.
✗ Incorrect
.navigationTitle with displayMode and .toolbar are the current correct modifiers. .navigationBarTitle is deprecated. The order in C is correct and compiles.
🔧 Debug
expert2:00remaining
Why does this modifier chain cause a runtime crash?
Examine this SwiftUI code. Why does it crash at runtime?
iOS Swift
Text("Crash") .frame(width: 100, height: 50) .background(Color.red) .clipShape(Circle())
Attempts:
2 left
💡 Hint
Think about shape clipping on rectangular frames.
✗ Incorrect
Clipping a rectangular frame with a circle shape can cause layout conflicts leading to runtime issues. The order and shape mismatch cause the crash.