3
votes

I'm having this odd issue with macOS Montery 3 & Xcode 13 Beta 3, where I get this error with List's and animations:

[General] Row index 0 out of row range (numberOfRows: 0) for <SwiftUIListCoreOutlineView: 0x133885000>

Its kinda hard to explain, but heres a simple reproduction:

Minimal Reproducible Example

  1. Create a new SwiftUI macOS application
  2. Paste this code:
struct ContentView: View {
    @State var items = ["Item"]
    
    @ViewBuilder var mainView: some View {
        if items.isEmpty {
            Text("Im empty")
        }
        else {
            List(items, id: \.self) {s in
                Text(s)
            }
        }
    }
    var body: some View {
        NavigationView {
            mainView
                .toolbar {
                    Button(action: {
                        withAnimation {
                            items.removeAll()
                        }
                    }) {
                        Image(systemName: "minus")
                    }
                }
            Text("Second")
        }
    }
}
  1. Run the app, and try resizing the sidebar. (You should be able to)
  2. Then press the minus button on the toolbar. This simply removes all the items.
  3. Then, the resizing of the sidebar should be broken. You might also get a bunch of errors in the console.

Is anybody able to reproduce this issue, and is it a bug in SwiftUI?

1

1 Answers

0
votes

got the same behavior. The code works well if I remove the "withAnimation". Or put "items.removeAll()" outside the "withAnimation"