NSPredicate aggregated operations with NONE

How to create a predicate that can be obtained: all questions do not contain answer.correct = "1".

The following predicate does not work if the returned array contains "0" and "1":

[NSPredicate predicateWithFormat:@"NONE answers.correct IN %@", [NSArray arrayWithObject:@"1"]];

Also tried with NOT (ANYWHERE ...): same result

This is mistake?

DataModel

+5
source share
1 answer

Short answer: To get all objects that have no "answer" with "correct == 1", use the following SUBQUERY:

[NSPredicate predicateWithFormat:@"SUBQUERY(answers, $a, $a.correct == 1).@count == 0"]

Explanation: Both predicates

[NSPredicate predicateWithFormat:@"NONE answers.correct == 1"]
[NSPredicate predicateWithFormat:@"NOT (ANY answers.correct == 1)"]

should work (as I understand the words NOT and ANY), but they do not. They return the same result as

[NSPredicate predicateWithFormat:@"ANY answers.correct != 1"]

, -com.apple.CoreData.SQLDebug 3 SQL select.

Core Data. SUBQUERY .

+17

All Articles