Created
June 15, 2021 06:09
-
-
Save shameemreza/73bea1f5487bb462829785ecc187b219 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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