Skip to content

Instantly share code, notes, and snippets.

@benigumocom
Last active December 20, 2023 15:41
Show Gist options
  • Save benigumocom/5b9a92d6e9121aafe554b897b058f6e5 to your computer and use it in GitHub Desktop.
Save benigumocom/5b9a92d6e9121aafe554b897b058f6e5 to your computer and use it in GitHub Desktop.
Jetpack Compose から SwiftUI に来ましたが今の謎をどうにかしたい 😩 👉 https://android.benigumo.com/20231221/swiftui-property-wrapper/
import SwiftUI
import SwiftData
import BackyardBirdsData
struct BirdsSearchResults<Content: View>: View {
@Binding var searchText: String
@Query private var birds: [Bird]
private var content: (Bird) -> Content
init(searchText: Binding<String>, @ViewBuilder content: @escaping (Bird) -> Content) {
_searchText = searchText
_birds = Query(sort: \.creationDate)
self.content = content
}
var body: some View {
if $searchText.wrappedValue.isEmpty {
ForEach(birds, content: content)
} else {
ForEach(birds.filter {
$0.speciesName.contains($searchText.wrappedValue)
}, content: content)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment