I would like to have a SwiftData predicate that filters against an array of PersistentIdentifiers.
A trivial use case could filtering Posts by one or more Categories. This sounds like something that must be trivial to do.
When doing the following, however:
let categoryIds: [PersistentIdentifier] = categoryFilter.map { $0.id }
let pred = #Predicate<Post> {
if let catId = $0.category?.persistentModelID {
return categoryIds.contains(catId)
} else {
return false
}
}
The code compiles, but produces the following runtime exception (XCode 26 beta, iOS 26 simulator):
'NSInvalidArgumentException', reason: 'unimplemented SQL generation for predicate : (TERNARY(item != nil, item, nil) IN {}) (bad LHS)'
Strangely, the same code works if the array to filter against is an array of a primitive type, e.g. String or Int.
What is going wrong here and what could be a possible workaround?