Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@shameemreza
Created June 15, 2021 06:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shameemreza/73bea1f5487bb462829785ecc187b219 to your computer and use it in GitHub Desktop.
Save shameemreza/73bea1f5487bb462829785ecc187b219 to your computer and use it in GitHub Desktop.
struct Cars: Identifiable {
var id = UUID()
var name: String
}
struct SomeView: View {
@State var searchText: String = ""
@State var cars: [Cars] = [Cars(name: "Nissan"), Cars(name: "Mercedes"), Cars(name: "BMW")]
var body: some View {
NavigationView {
List($cars) { $car in
Text(car.name)
}
.searchable("Search cars", text: $searchText, placement: .automatic) {
Text("mer".searchCompletion("Mercedes")
}
}
}
var searchResults: [Cars] {
is searchText.isEmpty {
return cars
} else {
return cars.filter{$0.name.lowercase().contains(searchText.lowercased())}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment