Bird
0
0

Identify the error in this SwiftUI code snippet:

medium📝 Debug Q6 of 15
iOS Swift - SwiftUI Layout
Identify the error in this SwiftUI code snippet:
Text("Hello")
  .background(Color.red)
  .overlay(Color.blue)
AThe overlay color will not be visible because background covers it.
BThe code is correct and will show blue overlay on red background.
CThe modifiers are in wrong order; overlay must come before background.
DColor cannot be used directly in overlay or background.
Step-by-Step Solution
Solution:
  1. Step 1: Understand modifier order

    Modifiers apply in order; background behind, overlay on top, so blue overlay appears above red background.
  2. Step 2: Check if Color can be used directly

    Color views can be used directly in both background and overlay modifiers.
  3. Final Answer:

    The code is correct and will show blue overlay on red background. -> Option B
  4. Quick Check:

    Overlay on top, background behind = The code is correct and will show blue overlay on red background. [OK]
Quick Trick: Overlay is always on top, background behind [OK]
Common Mistakes:
  • Thinking background covers overlay
  • Believing modifier order is wrong here
  • Assuming Color can't be used directly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes