ios - 使用 NSPredicate 搜索一系列 NSString

标签 ios objective-c nspredicate

我正在尝试使用 NSPredicate 搜索 Core Data 以查找与多个 NSStrings 匹配的所有结果。以下适用于使用“a”查找结果,但如何设置 NSPredicate 以查找“a”、“b”和“c”?

NSPredicate *predicate = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"Result ==  'a'"]];

最佳答案

NSPredicate *predicate = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"Result ==  'a' OR Result ==  'b' OR Result ==  'c'"]];

EDIT:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"self.Result IN %@",[NSArray arrayWithObjects:@"a",@"b",@"c", nil]];

关于ios - 使用 NSPredicate 搜索一系列 NSString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26688719/

相关文章:

iphone - Dealloc'd 谓词导致 iPhone 应用程序崩溃!

cocoa - NSPredicate 内存问题

ios - UIActionsheet 背景清晰颜色

ios - 来自 AVDepthData 的深度图不同于 Photoshop 中的 HEIC 文件深度数据

ios - 将我在 Parse 中的列设置为 Swift 中 ObjectId 的指针

ios - 多行 UILabel 上的 NSAttributedString 切断第一行

swift - 具有基于递归关系的条件的 NSPredicate - Swift - 核心数据

ios - 获取操作表内标题 View 的高度

ios - Admob 导致 Cocos2d 触摸延迟

ios - 在 coredata 中预填充数据