ios - 如何解决 NSPredicate error 'Can' t use in/contains operator with collection 8 (not a collection)

标签 ios iphone objective-c nspredicate

我尝试根据初始查询的心情来预测我的核心日期,所有心情都设置为 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/

相关文章:

ios - 我的 copy-frameworks Run Script 应该如何看待嵌套的 Carthage 框架?

iOS Mystery crash w libsystem_kernel.dylib

ios - 删除桥接头步骤

ios - MKAnnotation 捏住 map 时旋转

ios - WKWebView 在加载另一个 URL 时不会重新呈现内容

ios - 谷歌登录 Flutter : Error Code -4

ios - 单击警报按钮不起作用时更改 View

ios - 如何初始化 VC 或 Class iOS, Objective C

iphone - 通过设置 Root View Controller 来切换 View 有什么问题吗?

iphone - 触摸(点击)事件的顺序