Search code examples
objective-ccocoacocoa-touchkey-value-coding

Cocoa KVC: "class is not key value coding-compliant"


I'm trying to update some properties with KVC. The properties have been synthesized.

This line works:

myObject.value = intValue;

This doesn't work:

[self setValue:[NSNumber numberWithInt:intValue] forKey:@"myObject.value"];

And blows up with: Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<MyViewController 0xd1cec0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key myObject.value.'

Yet further up the method (awakeFromNib) other instances of the same class respond fine to setValue:forKey: calls. The only difference is this particular instance was created and wired up in IB.


Solution

  • It's telling you that isn't a valid key for that object, and indeed it isn't: "myObject.value" is a keypath, not a single key.