核心数据不支持使用ALL和IN的谓词

Tho*_*lin 4 core-data objective-c nspredicate ios

我有这样的请求:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY attributes.attribute.attributeId IN %@", attributeIds];
Run Code Online (Sandbox Code Playgroud)

这将返回一个对象列表,其中包含我设置的一个或多个属性.我想得到一个包含我通过的所有属性的对象列表,所以我尝试了:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ALL attributes.attribute.attributeId IN %@", attributeIds];
Run Code Online (Sandbox Code Playgroud)

但我有一个例外:

'NSInvalidArgumentException', reason: 'Unsupported predicate (null)'
Run Code Online (Sandbox Code Playgroud)

无论如何,我甚至不确定这是正确的要求.假设我有属性列表:[red, green, blue],如何获得至少具有这些属性的所有对象?

* Object_1 (red, green, blue)
* Object_2 (red, green, blue, yellow, brown)
* Object_3 (red, green blue, black, brown)
Run Code Online (Sandbox Code Playgroud)

但不是Object_4 (red, green, yellow)因为它没有blue属性(请注意我ANY按照预期获取了我的获取请求的所有4个对象)

编辑,相关问题:如果我想完全匹配怎么办?所以[red, green, blue]我只能得到Object_1


编辑2:我设法回答了这两个问题,但我有一个新问题

Tho*_*lin 6

获取列表中至少包含所有属性的所有对象

NSPredicate *objectsThatContainsAtLeastAllAttributesInList =
    [NSPredicate predicateWithFormat:
        @"SUBQUERY(attributes, $s, $s.attribute.attributeId IN %@).@count == %d", attributeIds, [attributeIds count]];    
Run Code Online (Sandbox Code Playgroud)

获取仅包含列表中属性的所有对象

NSPredicate *objectsWhoseAttributesAreInList =
    [NSPredicate predicateWithFormat:
        @"attributes.@count == %d AND SUBQUERY(attributes, $s, $s.attributes.id IN %@).@count == %d", [attributeIds count], attributeIds, [attributeIds count]];
Run Code Online (Sandbox Code Playgroud)