Bird
0
0

Identify the error in this SwiftUI code snippet: HStack { Text("Left") Spacer() Text("Right") }.padding(.horizontal 20)

medium📝 Debug Q6 of 15
iOS Swift - SwiftUI Layout
Identify the error in this SwiftUI code snippet: HStack { Text("Left") Spacer() Text("Right") }.padding(.horizontal 20)
AMissing comma in padding modifier
BSpacer() cannot be used inside HStack
CText views must have fixed width
Dpadding modifier should be .padding(20)
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax of padding modifier

    padding(.horizontal 20) is missing a comma between parameters.
  2. Step 2: Correct syntax requires comma

    It should be padding(.horizontal, 20) with a comma separating arguments.
  3. Final Answer:

    Missing comma in padding modifier -> Option A
  4. Quick Check:

    Modifiers need commas between parameters [OK]
Quick Trick: Always separate modifier parameters with commas [OK]
Common Mistakes:
  • Omitting commas in modifiers
  • Thinking Spacer() is invalid in HStack
  • Misusing padding syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes