0

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?

CGee
  • 1,650
  • 5
  • 20
  • 31
  • Could you say something about your model? – Lorenzo B Sep 29 '12 at 10:21
  • Of course, what would you like to know? I can say that the "aBooleanKey" is a BOOLEAN value in the model. What else is important? – CGee Sep 29 '12 at 10:44
  • 1
    If you change the name of that attribute (e.g. `booleanStatus`), does the problem persist? – Lorenzo B Sep 29 '12 at 10:48
  • You need to remove the app and ricreate it, since you have changed the model. – Lorenzo B Sep 29 '12 at 10:49
  • Thanks Flex_Addicted. Although I still don't understand what the problem was – deleting the old attribute and adding a new one with another name plus lightweight migration solved my problem. – CGee Sep 29 '12 at 11:00
  • If you want, I could convert my comment as an answer and you could mark it as correct. What do you think? In this manner other people can see the solution. Le me know. Cheers. – Lorenzo B Sep 29 '12 at 12:29
  • Hmm ... may help some people, so let's do it! :) – CGee Sep 30 '12 at 10:33
  • You could also reply to your question (providing that solution) and mark it as correct. ;) As you prefer. – Lorenzo B Sep 30 '12 at 10:52
  • 1
    Since I wasn't the one with the idea I would prefer the previous proposal. :) – CGee Sep 30 '12 at 11:00

1 Answers1

1

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.

Lorenzo B
  • 33,216
  • 24
  • 116
  • 190
  • 1
    Thanks Flex_Addicted. Although I still don't understand what the problem was – deleting the old attribute and adding a new one with another name plus lightweight migration solved my problem. – CGee Sep 30 '12 at 11:07