I am fetching a set of objects from a Core Data persistent store using a fetch request and a predicate. My current predicate simply checks whether an attribute is >= a certain value. This all works great, except that I want to finally exclude any objects that are currently held in an array.
I basically need to be able to exclude a set of objects, and the only way I think I can do this is to be able to get a list of objectID from my managed objects array, and create another expression in my predicate to ensure that any objects returned don’t have the same objectID. I.E.@"ANY records.objectID NOT IN %@", arrayOfObjectID.
How can I do this?
A predicate like
where the entity of the fetch request is the entity of objects in the array, should do what you want. This can, of course be combined with other clauses in a single predicate for a fetch request.
In general, object comparisons (e.g
self == %@orself IN %@) compare onobjectIDin Core Data queries. The argument can either be an NSManagedObject instance or anNSMangedObjectIDinstance. So the predicate format above could takearrayOfExcludedObjectsor[arrayOfExcludedObjects valueForKey:@"objectID"]as the argument.