0

On macOS I get an unexpected crash with the following code when entering a search that is not in the data (e.g. "100"). It does NOT crash on iOS with the same code.

Any hints appreciated.

struct ContentView: View {
    
    let data: [Int] = (1...20).map { $0 }

    var filteredData: [Int] {
        if search.isEmpty {
            return data
        } else {
            return data.filter { String($0).contains(search) }
        }
    }

    @State private var selection: Int? = nil
    @State private var search = ""

    var body: some View {
        
        NavigationStack {
            List(selection: $selection) {
                DisclosureGroup("Group") {
                    ForEach(filteredData, id: \.self) { item in
                        Text("\(item)")
                    }
                }
            }
            .searchable(text: $search)
        }
    }
}
ChrisR
  • 9,523
  • 1
  • 8
  • 26

0 Answers0