Member-only story

Optimizing SwiftUI Lists: How to Make Scrollable Views Smooth and Fast

Simple techniques to enhance List performance in SwiftUI for a seamless user experience.

Pavlos Simas
4 min readOct 31, 2024
Photo by Ales Nesetril on Unsplash

Using List in SwiftUI makes it easy to create scrollable, data-driven views, but performance issues can arise when working with large data sets. SwiftUI’s declarative approach is powerful but requires some specific techniques to ensure your lists scroll smoothly. In this article, we’ll explore practical tips for optimizing SwiftUI lists, managing data efficiently, and creating smooth, responsive experiences for users.

1. Use Lightweight Cells with Lazy Stacks

By default, SwiftUI’s List uses VStack or HStack to stack items vertically or horizontally. To improve performance, use LazyVStack or LazyHStack instead. Lazy stacks only create views that are visible, saving memory and reducing the rendering workload.

Example of Lazy Stacks in a List

struct ContentView: View {
let items = Array(0..<1000)

var body: some View {
ScrollView {
LazyVStack {
ForEach(items, id: \.self) { item in
Text("Item \(item)")
.padding()
}
}

--

--

Pavlos Simas
Pavlos Simas

Written by Pavlos Simas

iOS Developer, with passion about Development, Marketing and Finance. Join Medium from the following link: https://simaspavlos.medium.com/membership

No responses yet

Write a response