Core Data: Query objectIDs in a predicate?

A predicate like

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"NOT (self IN %@)", arrayOfExcludedObjects];

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 == %@ or self IN %@) compare on objectID in Core Data queries. The argument can either be an NSManagedObject instance or an NSMangedObjectID instance. So the predicate format above could take arrayOfExcludedObjects or [arrayOfExcludedObjects valueForKey:@"objectID"] as the argument.

Leave a Comment