How to create a Core Data predicate to test that a relation contains all given objects?

The following predicate could work:

[NSPredicate predicateWithFormat:@"(items.@count == %d) AND (SUBQUERY(items, $x, $x IN %@).@count == %d)",
                      itemSet.count, itemSet, itemSet.count];

The predicate checks first that the number of items is equal to the size of the given itemSet, and then checks that the number of items which are member of itemSet is also equal to the size of itemSet. If both are true, then items must be equal to itemSet.

Leave a Comment