开发者

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

开发者 https://www.devze.com 2023-02-21 21:14 出处:网络
There\'s no way this question hasn\'t been asked before but I cannot find a clear answer anywhere. I have Co开发者_StackOverflow中文版re Data entities that have optional \'Integer 32\' attributes. I\

There's no way this question hasn't been asked before but I cannot find a clear answer anywhere.

I have Co开发者_StackOverflow中文版re Data entities that have optional 'Integer 32' attributes. I'm trying to setup a predicate to retrieve all objects where that attribute equals zero but is not 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.


This may be a simple typo, but I believe you want the predicate

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


Why don't you try using optional 'String' attributes instead and then converting them to integers.
Alternatively, you can use a '-1' to indicate invalid values and put that as the default value of your attribute.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号