ios - iOS/Objective-C:核心数据提取中的NSPredicate和NULL值

标签 ios core-data nspredicate

我正在尝试获取NSNumber属性中值不为1的项目。我要获取的某些项目根本没有设置属性,因此具有NSNull值。如何获取不是1但可能是NSNull的项目?

该属性是NSNumber,对于我应该搜索1还是@1,我也有些困惑。

以下代码在我要包括NSNull值时将它们排除在外:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"&hasserverid!=1"];

感谢您的任何建议。

最佳答案

您可以使用OR明确测试这两种情况:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"hasserverid != YES OR hasserverid == NULL"];

用您的属性名称,我假设当您说1时,您实际上是在指值true。在谓词格式中使用YES而不是1将使您的谓词更易读。

关于ios - iOS/Objective-C:核心数据提取中的NSPredicate和NULL值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50466390/

相关文章:

objective-c - +entityForName : nil is not a legal NSManagedObjectContext parameter searching for entity name

ios - 核心数据崩溃:集合在枚举时发生了变异

swift - NSManagedObjectID 与自定义 UUID 标识符属性 - 获取性能

ios - 创建新对象时查询核心数据的特定属性,如果存在则返回对象,如果不存在则创建一个新对象

ios - 提高大型数据集上谓词的性能

ios - 看似无关的方法中的预期表达?

ios - NSInvalidArgumentException 跟踪 : < redacted> < redacted> < redacted> in iOS 6

ios - 调整导航 Controller 大小仅适用于纵向?

ios - Parse.com : [task. 结果 filteredArrayUsingPredicate] 使用 Xcode 7 抛出 objec_exception_thrown

ios - 当用户在 iOS 中滚动 UITableView 时,UIProgressView 暂停进度