Hi all,
I am starting using the new amazing SwiftData and I really like it!
I have a question regarding how to pass the filter predicate from the parent view.
In my app I have a simple case where I have a package that contains multiple items.
When I package is selected a view is pushed with the list of items in that package.
The Items view has a query as following:
struct ScoreListView: View {
[.....]
@Query(filter: #Predicate<SWDItem> { item in
item.package?.id == selectedPackage.id
} ,sort: \.timestamp) var items: [SWDItem]
[.....]
var body: some View {
[...]
}
The problem is that selectedPackage is not "yet" available when defining the @Query and I have the classic error "Cannot use instance member 'selectedPackage' within property initializer; property initializers run before 'self' is available".
How can I structure the code to have the selected package available when the @Query is defined?
Thank you a lot