我尝试根据初始查询的心情来预测我的核心日期,所有心情都设置为 8。 我将每秒从 0 - 7 调用以更新 tableview。
但是我得到了
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];
最佳答案
这可能意味着 mood
属性存储为数字,而不是字符串。 “CONTAINS”仅适用于字符串。以下谓词应该有效:
NSNumber *mood = @(7);
NSString *filter = @"%K == %@";
NSPredicate *getMoodPred = [NSPredicate predicateWithFormat:filter, @"mood", mood];
在 rhs 上使用 NSNumber
和 ==
作为比较器。
关于ios - 如何解决 NSPredicate error 'Can' t use in/contains operator with collection 8 (not a collection),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20606453/