Bird
0
0

Identify the error in this SwiftUI ScrollView code:

medium📝 Debug Q6 of 15
iOS Swift - SwiftUI Layout
Identify the error in this SwiftUI ScrollView code:
ScrollView(.horizontal) {
  VStack {
    Text("Hello")
    Text("World")
  }
}
AVStack inside horizontal ScrollView causes layout issues
BNo error; this code works correctly
CScrollView must have HStack for horizontal scrolling
DText views cannot be inside VStack
Step-by-Step Solution
Solution:
  1. Step 1: Understand ScrollView direction and content layout

    Horizontal ScrollView expects content arranged horizontally for smooth scrolling.
  2. Step 2: Analyze VStack inside horizontal ScrollView

    VStack arranges vertically, which can cause layout issues or unexpected scrolling behavior inside horizontal ScrollView.
  3. Final Answer:

    VStack inside horizontal ScrollView causes layout issues -> Option A
  4. Quick Check:

    Horizontal ScrollView + VStack = layout issue [OK]
Quick Trick: Match ScrollView direction with content layout (HStack or VStack) [OK]
Common Mistakes:
  • Assuming no error
  • Thinking HStack is mandatory but ignoring layout mismatch
  • Believing Text can't be inside VStack

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes