Bird
0
0

Given this SwiftUI code, what will happen when the content height exceeds the screen height?

medium📝 Predict Output Q5 of 15
iOS Swift - SwiftUI Layout
Given this SwiftUI code, what will happen when the content height exceeds the screen height?
ScrollView {
  VStack {
    ForEach(0..<50) { i in
      Text("Item \(i)")
    }
  }
}
AOnly the first 10 items are visible, no scrolling
BThe app crashes due to too many views
CThe user can scroll vertically to see all 50 items
DThe items are clipped and not scrollable
Step-by-Step Solution
Solution:
  1. Step 1: Understand default ScrollView direction

    ScrollView without parameters scrolls vertically by default.
  2. Step 2: Analyze content size and scrolling

    VStack with 50 items exceeds screen height, so vertical scrolling allows viewing all items.
  3. Final Answer:

    User can scroll vertically to see all 50 items -> Option C
  4. Quick Check:

    Default ScrollView = vertical scroll [OK]
Quick Trick: ScrollView defaults to vertical scrolling [OK]
Common Mistakes:
  • Thinking only 10 items show
  • Assuming app crashes with many views
  • Believing content is clipped without scroll

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes