SwiftUI - Prevent reloading entire list when a new row is added

Hi all, I’m just getting started with SwiftUI.

I’ve got a List view wrapped in a navigation view, that displays a row for each item in a @State array, and a navigation bar item that displays another view when pressed. This second view takes a binding to the array as a parameter and appends a new item to it. The problem is that the List view appears to be reloading the entire array when a new row is added rather than just the new row. How can I prevent this?

I don’t believe there is a way. List is a View, and when the contents of the View change, the View is recreated.

Depending on what your app is doing, you could try using ScrollView and LazyVStack.

ListVsLazy.zip (27.7 KB)

In this app it takes a couple of seconds to add while showing a List, but not when showing the lazy stack.

1 Like