Search code examples
iosobjective-cnspredicate

NSPredicate with ANY and "=nil" doesn't work


This condition works

NSPredicate *predicate = [NSPredicate predicateWithFormat:
       @"ANY region.beacons.major = %d",rangedBeacon.major.intValue];

But this not

NSPredicate *predicate = [NSPredicate predicateWithFormat:
       @"ANY region.beacons.minor = nil"];

beacons is a list inside region object. Major and minor have type NSNumber


Solution

  • I found solution

    Because of ANY and "=nil" can't be in the same condition (explanation is here Core Data, NSPredicate, ANY key.path == nil)? solution of this problem looks like:

    NSPredicate *predicate = [NSPredicate predicateWithFormat:
          @"SUBQUERY(region.beacons, $x, $x.minor == nil)"];