iOS Swift - Lists and Data Display
Why does the following SwiftUI code produce a compile-time error?
@State private var searchText = ""
let items = ["apple", "banana"]
var body: some View {
List(filteredItems, id: \.self) { item in
Text(item)
}
.searchable(text: $searchText)
}
var filteredItems: [String] {
items.filter { $0.contains(searchText) }
}