Bird
0
0

Which of the following is the correct syntax to create a grid with three fixed-width columns using LazyVGrid?

easy📝 Syntax Q3 of 15
iOS Swift - SwiftUI Layout
Which of the following is the correct syntax to create a grid with three fixed-width columns using LazyVGrid?
ALazyVGrid(rows: [GridItem(.fixed(100)), GridItem(.fixed(100)), GridItem(.fixed(100))]) { ... }
BLazyVGrid(columns: [GridItem(.flexible()), GridItem(.flexible())]) { ... }
CLazyHGrid(columns: [GridItem(.fixed(100)), GridItem(.fixed(100)), GridItem(.fixed(100))]) { ... }
DLazyVGrid(columns: [GridItem(.fixed(100)), GridItem(.fixed(100)), GridItem(.fixed(100))]) { ... }
Step-by-Step Solution
Solution:
  1. Step 1: Understand grid parameters

    LazyVGrid uses columns parameter to define columns; fixed width uses .fixed().
  2. Step 2: Analyze options

    LazyVGrid(columns: [GridItem(.fixed(100)), GridItem(.fixed(100)), GridItem(.fixed(100))]) { ... } correctly defines three fixed columns. LazyVGrid(rows: [GridItem(.fixed(100)), GridItem(.fixed(100)), GridItem(.fixed(100))]) { ... } wrongly uses rows with LazyVGrid. LazyHGrid(columns: [GridItem(.fixed(100)), GridItem(.fixed(100)), GridItem(.fixed(100))]) { ... } uses LazyHGrid. LazyVGrid(columns: [GridItem(.flexible()), GridItem(.flexible())]) { ... } defines only two flexible columns.
  3. Final Answer:

    LazyVGrid with three fixed columns -> Option D
  4. Quick Check:

    Fixed columns in LazyVGrid = columns with .fixed [OK]
Quick Trick: LazyVGrid uses columns parameter, LazyHGrid uses rows [OK]
Common Mistakes:
  • Using rows instead of columns in LazyVGrid
  • Confusing LazyVGrid with LazyHGrid syntax
  • Incorrect number of columns defined

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes