Bird
0
0

What will be the color of the text displayed by this SwiftUI code?

medium📝 Predict Output Q13 of 15
iOS Swift - SwiftUI Basics
What will be the color of the text displayed by this SwiftUI code?
Text("Hello")
  .foregroundColor(.blue)
  .foregroundColor(.red)
ABlue
BBlack (default)
CPurple
DRed
Step-by-Step Solution
Solution:
  1. Step 1: Understand modifier order

    Modifiers apply in order, and each returns a new view. The last .foregroundColor() overrides the previous one.
  2. Step 2: Analyze the code

    The first sets color to blue, the second immediately changes it to red, so red is final.
  3. Final Answer:

    Red -> Option D
  4. Quick Check:

    Last modifier wins for same property [OK]
Quick Trick: Last color modifier sets final text color [OK]
Common Mistakes:
  • Assuming colors mix to purple
  • Thinking first modifier stays active
  • Ignoring modifier order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes