Bird
0
0

Given this code:

medium📝 ui behavior Q5 of 15
iOS Swift - SwiftUI Layout
Given this code:
LazyHGrid(rows: [GridItem(.fixed(40)), GridItem(.fixed(40))]) {
  ForEach(0..<3) { i in
    Text("Row \(i)")
  }
}

How many rows and columns will be visible?
A2 rows and 2 columns
B2 rows and 3 columns
C3 rows and 2 columns
D3 rows and 3 columns
Step-by-Step Solution
Solution:
  1. Step 1: Understand LazyHGrid layout

    LazyHGrid arranges items horizontally with fixed rows.
  2. Step 2: Count rows and columns

    There are 2 fixed rows, and 3 items fill columns horizontally, so 3 columns appear.
  3. Final Answer:

    2 rows and 3 columns -> Option B
  4. Quick Check:

    LazyHGrid rows fixed, columns grow with items [OK]
Quick Trick: LazyHGrid rows fixed; columns expand with items [OK]
Common Mistakes:
  • Confusing rows and columns in LazyHGrid
  • Assuming rows equal number of items
  • Miscounting columns

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes