2016-09-13 12 views
0

這種情況適用NSPredicate任何及「=無」不工作

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

但這並不

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

信標是區域內對象的列表。主要和次要有型的NSNumber

+0

您的次要價值是什麼?它是零嗎? – Sujit

+0

它可以是零。無 - 這不是零。 –

+0

可以打印信標 – Sujit

回答

0

我找到了解決方案

因爲任何和「=無」不能在相同的條件下(解釋是這裏Core Data, NSPredicate, ANY key.path == nil )?此問題的解決方案如下所示:

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

你可以試試這個:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY region.beacons.minor = $minor"]; 
predicate = [predicate predicateWithSubstitutionVariables: 
[NSDictionary dictionaryWithObject:[NSNull null] forKey: @"minor"]]; 
+0

不,不幸的。 –

+0

你可以檢查這個鏈接,你說的主要和次要的是NSNumber,用於檢查空值: http://stackoverflow.com/questions/3716599/check-if-nsnumber-is-empty – ZetaPR