The PersistentIdentifier is basically an abstraction over the DB primary key, it's a Struct consisting of the storeId, the entity name, and the primary key. You can normally use PersistentIdentifiers in SwiftData predicates, so you can do { post in post.persistentModelID == aModelIdIAmLookingFor }
I cannot use the Category directly in the predicate, since it is an Optional. SwiftData predicates have problems comparing Optionals, such things only tend to work if you provide a default value before the comparison, e.g. (optionalString ?? "") == someNonOptionalString.
After some debugging, I have discovered that what is causing the issue, is not the PersistentIdentifier itself, but the if-let clause with the PersistentIdentifier. Thus, performing the optional binding with Category instead of the PersistentIdentifier makes it work:
if let cat = $0.category {
return categoryIds.contains(cat.persistentModelID)
}
Topic:
App & System Services
SubTopic:
iCloud & Data
Tags: