Discover how to make your app scroll smoothly even with thousands of items!
Why LazyVStack and LazyHStack in iOS Swift? - Purpose & Use Cases
Imagine you want to show a long list of photos or messages on your phone screen. If you try to create all those views at once, your app might slow down or even freeze.
Building all the views at once uses a lot of memory and takes time. This makes your app feel slow and can cause crashes, especially if the list is very long.
LazyVStack and LazyHStack create views only when they are about to appear on the screen. This way, your app stays fast and smooth, even with many items.
VStack {
ForEach(0..<1000) { i in
Text("Item \(i)")
}
}LazyVStack {
ForEach(0..<1000) { i in
Text("Item \(i)")
}
}You can build fast, smooth scrolling lists with many items without slowing down your app.
When you scroll through your photo gallery or chat messages, LazyVStack and LazyHStack help load only what you see, making scrolling smooth and quick.
Creating all views at once can slow down your app.
LazyVStack and LazyHStack build views only when needed.
This improves performance and user experience for long lists.