为什么我无法使用“说明”作为Core Data实体的属性名称? [英] Why can't I use "description" as an attribute name for a Core Data entity?

查看:127
本文介绍了为什么我无法使用“说明”作为Core Data实体的属性名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的Core Data实体,它有一个名为description的字符串属性。
当程序命中时,程序崩溃:

  valueForKey:@description



我将description属性更改为text,问题解决了。



为什么会发生这种情况?



description是Core Data中的保留关键字吗?



从NSObject调用描述方法?



如果存在这些保留的关键字,是否有引用?

解决方案

因为它与 NSObject 中的 -description 方法冲突Core Data动态生成属性访问器和mutator - 名为description的属性将需要创建一个名为 -description 的访问器方法。这些记录在核心数据编程指南中, NSPropertyDescription类参考


请注意,属性名称不能与NSObject或NSManagedObject的任何无参数方法名称相同。例如,您不能为属性指定名称description。 NSObject上有数百个方法可能与属性名称冲突 - 并且这个列表可以在没有来自框架或其他库的警告的情况下增长。你应该避免非常一般的单词(如字体和颜色)和与Cocoa范例重叠的单词或短语(如isEditing和objectSpecifier)。



I have a simple Core Data entity that had a string attribute named "description". The program crashes when it hits:

valueForKey:@"description"

I changed the "description" attribute to "text" and problem solved.

Why does this happen?

Is "description" a reserved key word in Core Data?

Is it related to calling the description method from NSObject?

Is there a reference to these reserved key words if they exist?

解决方案

Because it conflicts with the -description method in NSObject (recall that Core Data dynamically generates property accessors and mutators — a property named ‘description’ would require creating an accessor method called -description). This is documented in the Core Data Programming Guide and the NSPropertyDescription Class Reference:

Note that a property name cannot be the same as any no-parameter method name of NSObject or NSManagedObject. For example, you cannot give a property the name "description". There are hundreds of methods on NSObject which may conflict with property names—and this list can grow without warning from frameworks or other libraries. You should avoid very general words (like "font", and "color") and words or phrases which overlap with Cocoa paradigms (such as "isEditing" and "objectSpecifier").

这篇关于为什么我无法使用“说明”作为Core Data实体的属性名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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