In Xcode 16 and Xcode 16.1 beta 2 the lazy loading of list does not work properly. Tested on physical device with iOS 17.
Below is minimal code to reproduce this issue: You can see in the debug console how many child views are initialized based on the print statement.
import SwiftUI
@main
struct TestDemoApp: App {
let data = Array(1...1000)
var body: some Scene {
WindowGroup {
List(data, id: \.self) { item in
SomeView(item: item)
}
}
}
}
struct SomeView: View {
static var count = 0
let item: Int
init(item: Int){
self.item = item
Self.count += 1
print(Self.count)
}
var body: some View{
Text(String(item))
.frame(height: 100)
}
}
When the view is shown the List creates all child views at once as shown in the console output:
It does not loads only first 13 out of 1000 as it does in older xcode 15.2: As the List is quite often used component in Swiftui Apps, the apps will be slow, because all the data are loaded and the main thread will be stuck until all child views are loaded.