SwiftUIMidMCQ
What is `LazyVStack` vs `VStack` — when does it matter?
Test your knowledge:
Explanation & Code
Answer:
VStack renders all its children immediately. LazyVStack only renders views as they become visible on screen — essential for large lists.
Code Example:
// VStack — all 1000 rows created immediately
ScrollView {
VStack {
ForEach(0..<1000) { i in
ExpensiveRow(index: i) // all 1000 created at once ❌
}
}
}
// LazyVStack — only visible rows created
ScrollView {
LazyVStack {
ForEach(0..<1000) { i in
ExpensiveRow(index: i) // only ~20 visible rows created ✅
}
}
}
Rule of thumb:
- Use
VStackfor small fixed lists (under ~50 items) - Use
LazyVStackinsideScrollViewfor dynamic or large data sets Listuses lazy loading automatically
Rate your understanding: