ftchirou / PredicateKit

🎯 PredicateKit allows Swift developers to write expressive and type-safe predicates for CoreData using key-paths, comparisons and logical operators, literal values, and functions.
MIT License
406 stars 19 forks source link

Not able to compare an object that is not a primitive #19

Closed crewmate-app closed 1 year ago

crewmate-app commented 1 year ago

I'm getting this warning:

Operator function '==' requires that 'User' conform to 'Primitive'

When trying to compare an object within a predicate

Example: var predicate = (\CustomItemEntry.owner) == user

where owner/user are NSManagedObjects

ftchirou commented 1 year ago

Yes, for the moment you can only compare primitives. In your case, see if you can just compare a property that holds a unique value; perhaps an id: \CustomItemEntry.owner.id == user.id. I'll investigate whether it's worth adding an overload of == for Identifiables for cases like this.

ftchirou commented 1 year ago

Fixed in the latest release. You will now be able to compare objects that conform to Identifiable.