NSUnknownKeyException for existing and non-mistyped key

这一生的挚爱 提交于 2019-12-02 17:43:45

问题


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?


回答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.



来源:https://stackoverflow.com/questions/12651860/nsunknownkeyexception-for-existing-and-non-mistyped-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!