iOS Swift - Lists and Data Display
Given this SwiftUI code snippet, what will be the filtered list when the user types "cat" in the search bar?
struct ContentView: View {
@State private var searchText = ""
let animals = ["cat", "dog", "caterpillar", "bird"]
var filteredAnimals: [String] {
if searchText.isEmpty { return animals }
return animals.filter { $0.contains(searchText) }
}
var body: some View {
List(filteredAnimals, id: \.self) { animal in
Text(animal)
}
.searchable(text: $searchText)
}
}