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 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.
精彩评论