我以编程方式使用核心数据(即不使用.xcdatamodel
数据模型文件),其方式与 Apple 中描述的方式大致相同核心数据实用程序教程 http://developer.apple.com/documentation/Cocoa/Conceptual/CoreDataUtilityTutorial/CoreDataUtilityTutorial.pdf。所以我的问题是,当我尝试向具有以下类型的实体添加属性时NSBooleanAttributeType
,它有点麻烦。当我将它添加到我的NSManagedObject
子类头文件(在教程中,这将是Run.h
) as
@property (retain) BOOL *booleanProperty;
编译失败,说error: property 'booleanProperty' with 'retain' attribute must be of object type
.
好像Cocoa的某些地方使用NSNumber
对象来表示布尔值,所以我尝试将其设置为
@property (retain) NSNumber *booleanProperty;
反而。但是,这会引发以下运行时错误:
*** -[NSAttributeDescription _setManagedObjectModel:]: unrecognized selector sent to instance 0x101b470
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSAttributeDescription _setManagedObjectModel:]: unrecognized selector sent to instance 0x101b470'
使用 GDB,我可以追溯到源代码中将实体添加到托管对象模型的行:
[DVManagedObjectModel setEntities:[NSArray arrayWithObjects:myEntityWithABooleanAttribute, myOtherEntity]];
所以我的问题是:我应该在自定义类标头中将 booleanProperty 设置为什么类型?