Bird
0
0

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

medium📝 Predict Output Q4 of 15
iOS Swift - SwiftUI Basics
What will be the color of the text displayed by this SwiftUI code?
Text("Hello")
  .foregroundColor(.red)
  .foregroundColor(.blue)
ARed
BBlue
CPurple (blend of red and blue)
DBlack (default color)
Step-by-Step Solution
Solution:
  1. Step 1: Understand modifier order in SwiftUI

    Modifiers are applied in order, and later modifiers override earlier ones if they affect the same property.
  2. Step 2: Analyze the code

    The first foregroundColor(.red) is overridden by the second foregroundColor(.blue).
  3. Final Answer:

    Blue -> Option B
  4. Quick Check:

    Last foregroundColor modifier wins = B [OK]
Quick Trick: Last modifier of same type overrides previous ones [OK]
Common Mistakes:
  • Thinking colors blend automatically
  • Assuming first modifier applies
  • Ignoring modifier order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes