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
You must remember that we are only in the second beta of SwiftData and there are loads of bugs still floating around at the moment.
I just had a quick look at the release notes for beta 2 and look what I found:
SwiftData
Known Issues
• #Predicate does not support UUID, Date, and URL properties. (109539652)
So the problem is definitely with the predicate and the fact that you are comparing UUID
properties.