项目作者: Geri-Borbas

项目描述 :
🔍 SwiftUI search bar in the navigation bar.
高级语言: Swift
项目地址: git://github.com/Geri-Borbas/iOS.Blog.SwiftUI_Search_Bar_in_Navigation_Bar.git


SwiftUI Search Bar in Navigation Bar

🔍 SwiftUI (1) search bar in the navigation bar.

Complementary repository for article SwiftUI Search Bar in the Navigation Bar. For more details on motivations and implementation please refer to the full article, or lookup the basic usage example below otherwise.

  1. struct ContentView: View
  2. {
  3. var planets =
  4. ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"] +
  5. ["Ceres", "Pluto", "Haumea", "Makemake", "Eris"]
  6. @ObservedObject var searchBar: SearchBar = SearchBar()
  7. var body: some View {
  8. NavigationView {
  9. List {
  10. ForEach(
  11. planets.filter {
  12. searchBar.text.isEmpty ||
  13. $0.localizedStandardContains(searchBar.text)
  14. },
  15. id: \.self
  16. ) { eachPlanet in
  17. Text(eachPlanet)
  18. }
  19. }
  20. .navigationBarTitle("Planets")
  21. .add(self.searchBar)
  22. }
  23. }
  24. }

License

Licensed under the MIT License.