Core Data unsupported predicate with ALL and IN

前端 未结 1 1730
一生所求
一生所求 2020-12-30 15:23

I have a request like this :

NSPredicate *predicate = [NSPredicate predicateWithFormat:@\"ANY attributes.attribute.attributeId IN %@\", attributeIds];


        
相关标签:
1条回答
  • 2020-12-30 16:16

    Fetch all Objects that have at least all attributes in list

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

    Fetch all Objects that have only the attributes in list

    NSPredicate *objectsWhoseAttributesAreInList =
        [NSPredicate predicateWithFormat:
            @"attributes.@count == %d AND SUBQUERY(attributes, $s, $s.attributes.id IN %@).@count == %d", [attributeIds count], attributeIds, [attributeIds count]];
    
    0 讨论(0)
提交回复
热议问题