Core Data, NSPredicate and to-many key

后端 未结 4 1243
别跟我提以往
别跟我提以往 2020-12-08 06:45

I have a Core Data model in which a Task entity includes an optional to-many relationship excludedOccurrences. One of the properties of excludedOccurrences is start, which i

4条回答
  •  温柔的废话
    2020-12-08 07:23

    To test for an empty relationship you should compare the count of the to-many key to zero.

    [NSPredicate predicateWithFormat:@"excludedOccurrences.@count == 0"];
    

    As for your subpredicates, be aware that you can only have one of either the ALL or ANY modifiers in your final predicate, although you can use that modifier multiple times throughout the predicate.

    Not OK: ANY foo.bar = 1 AND ALL foo.baz = 2
    OK: ANY foo.bar = 1 AND !(ANY foo.baz != 2)

提交回复
热议问题