Thanks so much for your code
Post
Replies
Boosts
Views
Activity
With CoreData, I'm able to create fetchRequest based on relationship, for example, fetch all items belong to given box
let fetchRequest: NSFetchRequest<Item> = Item.fetchRequest()
fetchRequest.predicate = NSPredicate(format: "box == %@", box)
but it is not possible with Predicate
let predicate = #Predicate<Item> { item in
return item.box == box
}
I wonder, Is there any solution for this?
You need to add @Relationship to var students: [Student] in Department model, also:
import Foundation
import SwiftData
@Model
class Department {
...
@Relationship var students: [Student]
...
}