简体   繁体   English

核心数据-NSPredicate-查找等于0但不为Null的属性

[英]Core Data - NSPredicate - Finding properties that equal 0 but are not Null

There's no way this question hasn't been asked before but I cannot find a clear answer anywhere. 从来没有人问过这个问题,但是我在任何地方都找不到清晰的答案。

I have Core Data entities that have optional 'Integer 32' attributes. 我有具有可选的'Integer 32'属性的Core Data实体。 I'm trying to setup a predicate to retrieve all objects where that attribute equals zero but is not null. 我试图设置一个谓词以检索该属性等于零但不为null的所有对象。

attributes.power == nil AND attributes.power == 0

That's not doing the job. 那没有做。 This is returning no results. 这没有返回结果。 Removing the first half of the compound predicate returns zeros and nulls. 删除复合谓词的前半部分将返回零和零。

Any help is greatly appreciated. 任何帮助是极大的赞赏。

这可能是一个简单的错字,但我相信您想要谓词

attributes.power != nil AND attributes.power == 0

Why don't you try using optional 'String' attributes instead and then converting them to integers. 为什么不尝试使用可选的'String'属性,然后将其转换为整数。
Alternatively, you can use a '-1' to indicate invalid values and put that as the default value of your attribute. 另外,您可以使用'-1'表示无效值,并将其作为属性的默认值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM