Bird
0
0

Identify the error in this SwiftUI grid code:

medium📝 Debug Q14 of 15
iOS Swift - SwiftUI Layout
Identify the error in this SwiftUI grid code:
LazyVGrid(rows: [GridItem(.flexible())]) {
  Text("Hello")
  Text("World")
}
AText views cannot be inside LazyVGrid
BMissing ForEach loop for multiple items
CGridItem should be .fixed, not .flexible
DUsing 'rows' parameter instead of 'columns' in LazyVGrid
Step-by-Step Solution
Solution:
  1. Step 1: Check parameter name for LazyVGrid

    LazyVGrid requires 'columns' parameter, not 'rows'. Using 'rows' causes error.
  2. Step 2: Confirm other parts are valid

    Text views can be inside LazyVGrid; ForEach is optional for multiple views.
  3. Final Answer:

    Using 'rows' parameter instead of 'columns' in LazyVGrid -> Option D
  4. Quick Check:

    LazyVGrid needs 'columns' parameter [OK]
Quick Trick: LazyVGrid uses 'columns', not 'rows' [OK]
Common Mistakes:
  • Confusing rows and columns parameters
  • Thinking ForEach is mandatory
  • Misunderstanding GridItem types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes