I have a search button and a search bar in SwiftUi View. i'm try to run the function filter() when the user type in the Searchbar.
If I use the button to trig the action it works, but I want to trig the action when user typing in the bar.
I have tried with if else but give me a warning.
Generic parameter 'FalseContent' could not be inferred 1. In call to function 'buildEither(first:)' (SwiftUI.ViewBuilder)
here my code
struct ContentView: View {
@ObservedObject var dm: DataManager
@State private var searchTerm : String = ""
@State var filteredAirports: [AirportModel] = []
var body: some View {
VStack {
SearchBar(text: $searchTerm)
if searchTerm == "" {
/// don't do anything
} else {
self.dm.filter2(valoreSearhed: self.searchTerm, arrayTosearh: self.dm.airportVector)
}
List {
ForEach(dm.appoggio) { valore in
Text(valore.aptICAO)
}
}
}
}
}
``
Aucun commentaire:
Enregistrer un commentaire