Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why "NOT IN" does not work in this NSPredicate?

A.b and B.a are inverse to-many relationships. Why does this predicate for A work:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"NOT SELF IN %@", bObject.a];

while this one does not:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"NOT %@ IN b", bObject];

I think both predicates should give the same result — the collection of As that have no relation with bObject via a<-->b. But in fact, the first one gives the correct collection while the second one not.

Update:


Here is a sample project wherein A.b is embodied by Account.filtered_clients and B.a is embodied by Client.filtered_by.

Toggle commenting of line 143 and line 144 in MasterViewController.m to see the difference.

Please help me either find the bug in my code, or confirm it is a Core Data bug so I can report it to Apple. Thanks very much.

like image 533
an0 Avatar asked Jan 30 '12 14:01

an0


1 Answers

Here is another idea: maybe it is trying to "negate" the bObject with the NOT. Thus, try:

@"NOT (%@ IN b)"
like image 56
Mundi Avatar answered Oct 28 '22 02:10

Mundi