Last active
December 21, 2023 02:20
-
-
Save benigumocom/58309a8dcdcb1a3f7d31f8e44a106285 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: 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.wrappedValue | |
self.content = content | |
} | |
var body: some View { | |
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