Search code examples
iosobjective-cnsunknownkeyexception

Objective-C: Set boolean value in core data


In my data model, in an entity, I have an attribute that is a boolean. In the xcmodeldatad file, it is listed as:

need sync Boolean. In the NSmanagedobject file it is as follows:

.h file: @property (nonatomic, strong) NSNumber *needsync;//bool
.m file @dynamic needsync;

When saving the record after an edit, I use the following code that I have used numerous times before:

[list setValue:@0 forKey:@"needsync"];

However, it is throwing an exception when it reaches this line of

NSUnknownKeyException', reason: '[<__NSCFString 0x17409c4d0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key need sync.'

This is really baffling me and I wonder if anyone can spot error or has had this happen before.

Thank you.


Solution

  • Check your code again.

    The crash log shows that your object is a NSString, instead of YourList object, so, it doesn't has needsync property => crash.