现有和非错误键的NSUnknownKeyException [英] NSUnknownKeyException for existing and non-mistyped key

查看:133
本文介绍了现有和非错误键的NSUnknownKeyException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到以下输出:

  ***由于未捕获异常NSUnknownKeyException终止应用程序,原因: 
'[< NSManagedObject 0x21016610> setValue:forUndefinedKey:]:实体MyEntity是
不是键值编码符合键aBooleanKey。'

在获得输出之前运行的代码如下:

  self.name = [managedObject valueForKey:@name]; 
self.language = [managedObject valueForKey:@language];
self.ownerID = [managedObject valueForKey:@ownerID];
//下面的行是问题的范围:
self.aBooleanKey = [[managedObject valueForKey:@aBooleanKey] boolValue];

对于我来说,这看起来像是一个错误类型或东西,因为所有其他实体属性不会导致任何问题。但我检查过十二次,不能找到任何错误。这一切看起来都正确。一个星期前,这一切都很好 - 我没有改变任何东西。



还有一些其他地方,我做的事情与 managedObject ,同样所有其他属性工作正常,除了这一个。我尝试在Core Data存储中删除它,并重新输入它,但它没有解决问题。



这个错误还有其他原因吗?

这个问题是很奇怪的(有时工作,有时不是),所以我建议更改属性的名称(例如<$ c $ c> booleanStatus ),并验证问题是否仍然存在。



由于您更改了模型, ricreate它。或者,您可以对Core Data执行自动迁移。根据您的喜好。



希望它有所帮助。


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?

解决方案

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.

这篇关于现有和非错误键的NSUnknownKeyException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆