Crash on iOS 17 when using SwiftUI's List with dynamic data and onAppear
I'm learning this framework and I'm a bit lost with I'm stuck on something that should probably be simple... I'm experiencing a crash in my iOS 17 app when using SwiftUI's `List` view alongside dynamic data loading. The crash seems to occur intermittently when the `onAppear` modifier is triggered, especially when I scroll quickly through the list. The behavior message I receive is `Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM objectAtIndex:]: index 2 beyond bounds for empty NSArray'`. Here's a simplified version of my code: ```swift struct ContentView: View { @State private var items: [String] = [] var body: some View { List(items, id: \ .self) { item in Text(item) .onAppear { loadData() } } } private func loadData() { // Simulating an asynchronous data load DispatchQueue.global().async { sleep(1) // Simulate network delay DispatchQueue.main.async { let newItems = (0..<10).map { "Item \($0)" } self.items.append(contentsOf: newItems) } } } } ``` I've tried debouncing the data load and ensuring that I only append to the `items` array when it is not empty, but the scenario continues. Additionally, I've set up a breakpoint in the `loadData` method, and it appears to be called multiple times when scrolling through the list. Is there a way to prevent this crash from happening, or is there a better pattern to handle the dynamic loading of data in a `List`? Any insights would be appreciated. My development environment is Ubuntu. Am I missing something obvious? I'm coming from a different tech stack and learning Swift. Thanks for any help you can provide! The project is a REST API built with Swift. Could someone point me to the right documentation? This issue appeared after updating to Swift 3.9. Hoping someone can shed some light on this.