How can I get an object by a BOOL property? For example, if I have a custom object with a BOOL property completed, how can I get only the ones where completed = true
? I'm using Magical Record
[CustomObject MR_findByAttribute:@"completed" withValue:true];
The searchValue
argument of MR_findByAttribute:withValue:
must be a reference to an object, but true
is not a reference to an Objective-C object. It is a “primitive” value. You must wrap it in an NSValue
object.
Also, in Objective-C we normally use the constants YES
and NO
as the boolean constants.
You can get an NSValue
wrapper for YES
just by saying @YES
, so try this:
NSArray *completedObjects = [CustomObject MR_findByAttribute:@"completed"
withValue:@YES];