Bird
0
0

Identify the error in this SwiftUI code snippet:

medium📝 Debug Q14 of 15
iOS Swift - SwiftUI Layout
Identify the error in this SwiftUI code snippet:
Image(systemName: "star")
  .overlay(Circle().stroke(Color.blue))
  .background(Circle().fill(Color.yellow))
  .background(Color.red)
ACircle cannot be used inside overlay
BOverlay must come after all backgrounds
CImage cannot have background or overlay modifiers
DMultiple background modifiers cause only the first to apply
Step-by-Step Solution
Solution:
  1. Step 1: Analyze multiple background modifiers

    Applying .background() twice stacks backgrounds, but only the first background modifier applies directly behind the view, later ones get layered behind that.
  2. Step 2: Understand layering order

    The last .background(Color.red) will be behind the yellow circle background, so the red color might be hidden or layered behind unexpectedly.
  3. Final Answer:

    Multiple background modifiers cause only the first to apply -> Option D
  4. Quick Check:

    Last background behind earlier ones visually [OK]
Quick Trick: Multiple backgrounds stack but first is closest behind view [OK]
Common Mistakes:
  • Thinking overlay must be last
  • Believing Circle can't be overlay
  • Assuming Image can't have modifiers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes