Created
December 21, 2023 02:21
-
-
Save benigumocom/ce2fa6a437559ddd336efd423c240d25 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 BirdsSearchResults<Content: View>: View { | |
private var searchText: Binding<String> | |
private var content: (Bird) -> Content | |
@Query(sort: \Bird.creationDate) private var birds: [Bird] | |
init(searchText: Binding<String>, @ViewBuilder content: @escaping (Bird) -> Content) { | |
self.searchText = searchText | |
self.content = content | |
} | |
var body: some View { | |
let searchText = self.searchText.wrappedValue | |
let filtered = searchText.isEmpty ? birds : birds.filter { bird in | |
bird.speciesName.contains(searchText) | |
} | |
ForEach(filtered) { bird in | |
content(bird) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment