Question

I'm getting the following output:

*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason:
'[<NSManagedObject 0x21016610> setValue:forUndefinedKey:]: the entity MyEntity is
not key value coding-compliant for the key "aBooleanKey".'

The code that runs before I get the output is the following:

self.name = [managedObject valueForKey:@"name"];
self.language = [managedObject valueForKey:@"language"];
self.ownerID = [managedObject valueForKey:@"ownerID"];
// the following line is the scope of the problem:
self.aBooleanKey = [[managedObject valueForKey:@"aBooleanKey"] boolValue];

For me this looks like a mistyping or something, since all other entity attributes don't cause any problem. But I checked like twelve times and can't find any mistyping or so. It all looks just right. And a week ago it all worked just fine – I didn't change anything here.

Also there are a few other places where I do things with the managedObject and likewise all other attributes work just fine except this one. I tried deleting it in the Core Data store and retyping it, but it didn't solve the problem.

Are there any other reasons for this error?

Was it helpful?

Solution

The problem is quite strange (sometimes works, sometimes not), so I would suggest to change the name of the attribute (e.g. booleanStatus) and verify if the problem still persists or not.

Since you have changed the model you need to remove the app and ricreate it. Alternatively you could perform an automatic migration on Core Data. As you prefer.

Hope it helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top