Modifiers apply in order; the last .foregroundColor overrides previous ones.
Step 2: Identify final color
The last color set is .blue, so the text color will be blue.
Final Answer:
Blue -> Option C
Quick Check:
Last modifier wins = Blue [OK]
Hint: Last color modifier sets the text color [OK]
Common Mistakes:
Thinking colors combine or blend
Assuming first modifier applies
Ignoring modifier order
4. Identify the error in this SwiftUI code snippet:
Text("Hello")
.font(.title)
.padding(10, 20)
medium
A. Padding modifier does not accept two numbers like that
B. Text view cannot have modifiers chained
C. Font modifier .title is invalid
D. Padding modifier requires only one argument
Solution
Step 1: Check padding modifier syntax
The .padding() modifier accepts either no arguments, one argument for uniform padding, or a specific edge set with length.
Step 2: Analyze given arguments
Passing two numbers directly like .padding(10, 20) is invalid syntax in SwiftUI.
Final Answer:
Padding modifier does not accept two numbers like that -> Option A
Quick Check:
.padding() needs one argument or edge set [OK]
Hint: Padding takes one value or edges + value [OK]
Common Mistakes:
Passing multiple numbers directly to padding
Confusing padding with frame size
Assuming .title font is invalid
5. You want to create a Text view that shows "SwiftUI Rocks!" in large bold font, colored green, with padding around it. Which code snippet achieves this correctly?
hard
A. Text("SwiftUI Rocks!")
.font(.bold.largeTitle)
.foregroundColor(.green)
.padding()
B. Text("SwiftUI Rocks!")
.font(.largeTitle.bold)
.foregroundColor(.green)
.padding()
C. Text("SwiftUI Rocks!")
.font(.largeTitle)
.foregroundColor(.green.bold())
.padding()
D. Text("SwiftUI Rocks!")
.font(.largeTitle.bold())
.foregroundColor(.green)
.padding()
Solution
Step 1: Apply bold to font correctly
Using .font(.largeTitle.bold()) chains the bold style properly with the font size.
Step 2: Set color and padding
.foregroundColor(.green) sets the text color, and .padding() adds default padding around the text.
Step 3: Check other options for errors
Text("SwiftUI Rocks!")
.font(.largeTitle).bold()
.foregroundColor(.green)
.padding() tries to call .bold() separately which is invalid on Font. Text("SwiftUI Rocks!")
.font(.largeTitle)
.foregroundColor(.green.bold())
.padding() tries to bold the color, which is incorrect. Text("SwiftUI Rocks!")
.font(.bold.largeTitle)
.foregroundColor(.green)
.padding() uses invalid font syntax.
Final Answer:
Text("SwiftUI Rocks!")
.font(.largeTitle.bold())
.foregroundColor(.green)
.padding() -> Option D
Quick Check:
Use .font(.largeTitle.bold()) for bold large font [OK]
Hint: Chain .bold() inside .font() for bold text [OK]
Common Mistakes:
Calling .bold() separately on Text or Font
Trying to bold the color
Using invalid font modifier order
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.