I've been following a youtube tutorial for using LazyVStacks. https://www.youtube.com/watch?v=o6D7mUXjSmI
When I run the same code as per the tutorial, the LazyVStack using Xcode Version 13.2.1 (13C100) on a iPhone 11 Pro Max (running iOS 15.2) prints out 83 statements, when only 42 rows are in view. As per the tutorial it should only print 42 statements to the console.
Is this an Xcode/iOS bug? I'm unable to download the latest Xcode as my Mac doesn't support macOS 12.0 to verify.
Video tutorial showing on 42 print statements in the console on iPhone 11 Pro Max:

My code showing 83 print statements in the console on iPhone 11 Pro Max

import SwiftUI
struct SampleRow: View {
let id: Int
var body: some View {
Text("Row \(id)")
}
init(id: Int) {
print("Loading row \(id)")
self.id = id
}
}
struct ContentView: View {
var body: some View {
ScrollView {
LazyVStack {
ForEach(1...1000, id: \.self, content: SampleRow.init)
}
}
}
}


LazyVStackswill instantiate the number of views the OS thinks it may need based on a number of factors. This is part of the reason that you can't use.onAppear()to determine if a view is actually on screen. There is always a balance, that we don't control, between usage of resources and fluidity of scrolling. In other words, this is not a surprising result.