Last active
December 20, 2023 15:41
-
-
Save benigumocom/5b9a92d6e9121aafe554b897b058f6e5 to your computer and use it in GitHub Desktop.
Jetpack Compose から SwiftUI に来ましたが今の謎をどうにかしたい 😩 👉 https://android.benigumo.com/20231221/swiftui-property-wrapper/
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
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