2013-12-16 23 views
2

我試圖根據初始查詢的心情預測我的coredate所有的心情都設置爲8. 我會每秒調用0 - 7來更新tableview。如何解決NSPredicate錯誤'不能使用/包含運營商與集合8(不是一個集合)

,但我得到了

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't use in/contains operator with collection 8 (not a collection)' 

我應該使用CONTAINS或其他運營商的謂詞?

NSString* filter = @"%K CONTAINS[cd] %@"; 
NSPredicate *getMoodPred = [NSPredicate predicateWithFormat:filter, @"mood", mood]; 
NSLog(@"getmood %@",getMoodPred); //getmood mood CONTAINS[cd] "7" 
NSArray *getMoodArray = [[VPPCoreData sharedInstance]allObjectsForEntity:@"Song" orderBy:Nil filteredBy:getMoodPred]; 

回答

14

的大概意思是mood屬性存儲爲數字而不是字符串。 「CONTAINS」僅適用於字符串。下面的謂語應該工作:

NSNumber *mood = @(7); 
NSString *filter = @"%K == %@"; 
NSPredicate *getMoodPred = [NSPredicate predicateWithFormat:filter, @"mood", mood]; 

使用NSNumber在RHS和==的比較。

+0

謝謝,我錯過了! – Desmond

相關問題