Bird
0
0

Identify the error in this SwiftUI code snippet:

medium📝 Debug Q6 of 15
iOS Swift - SwiftUI Basics
Identify the error in this SwiftUI code snippet:
VStack {
  Text("Hello")
  Spacer.padding(20)
  Text("World")
}
APadding cannot be applied to Spacer
BSpacer is missing parentheses before padding modifier
CVStack cannot contain Spacer
DText views must be inside HStack
Step-by-Step Solution
Solution:
  1. Step 1: Check Spacer usage

    Spacer is a view and requires parentheses: Spacer() to be instantiated.
  2. Step 2: Analyze padding modifier

    Padding can be applied to Spacer(), but missing parentheses causes syntax error.
  3. Final Answer:

    Spacer is missing parentheses before padding modifier -> Option B
  4. Quick Check:

    Spacer() needs parentheses before modifiers [OK]
Quick Trick: Always write Spacer() with parentheses before modifiers [OK]
Common Mistakes:
  • Omitting parentheses on Spacer
  • Thinking padding disallowed on Spacer
  • Misunderstanding VStack content rules

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes