Bird
0
0

Identify the error in this SwiftUI ScrollView code:

medium📝 Debug Q14 of 15
iOS Swift - SwiftUI Layout
Identify the error in this SwiftUI ScrollView code:
ScrollView(.vertical) {
  VStack {
    Text("Hello")
  }
  Text("World")
}
AText views cannot be inside ScrollView
BScrollView cannot scroll vertically
CVStack cannot be used inside ScrollView
DMultiple views inside ScrollView without a container causes error
Step-by-Step Solution
Solution:
  1. Step 1: Check ScrollView content structure

    ScrollView expects a single child view. Here, VStack and Text("World") are siblings, which is invalid.
  2. Step 2: Understand SwiftUI container rules

    To fix, wrap VStack and Text("World") inside a container like VStack or Group.
  3. Final Answer:

    Multiple views inside ScrollView without a container causes error -> Option D
  4. Quick Check:

    ScrollView needs one child view [OK]
Quick Trick: ScrollView must have exactly one child view [OK]
Common Mistakes:
  • Adding multiple sibling views directly inside ScrollView
  • Thinking ScrollView can't scroll vertically
  • Believing Text can't be inside ScrollView

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes