Bird
0
0

Given this code:

medium📝 ui behavior Q5 of 15
iOS Swift - SwiftUI Layout
Given this code:
ScrollView(.horizontal) {
  LazyHStack {
    ForEach(0..<2, id: \.self) { i in
      Text("Number \(i)")
    }
  }
}

What will the user see?
AOnly "Number 0" visible, "Number 1" hidden
BA horizontal scrollable row with "Number 0" and "Number 1"
CA vertical scrollable column with "Number 0" and "Number 1"
DNo output due to syntax error
Step-by-Step Solution
Solution:
  1. Step 1: Understand ScrollView direction

    ScrollView(.horizontal) enables horizontal scrolling.
  2. Step 2: Understand LazyHStack layout

    LazyHStack arranges views horizontally and loads lazily.
  3. Step 3: ForEach creates two Text views

    ForEach(0..<2, id: \.self) creates "Number 0" and "Number 1" views.
  4. Final Answer:

    A horizontal scrollable row with "Number 0" and "Number 1" -> Option B
  5. Quick Check:

    Horizontal ScrollView + LazyHStack = horizontal list [OK]
Quick Trick: Match ScrollView axis with Lazy stack direction [OK]
Common Mistakes:
  • Confusing horizontal and vertical scrolling
  • Expecting only one item visible
  • Assuming syntax error in ForEach

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes