小编Mic*_*ink的帖子

Core Data实体中布尔属性的类型是什么?

我以编程方式使用Core Data(即不使用.xcdatamodel数据模型文件),其方式与Apple的Core Data Utility Tutorial中描述的方式大致相同.所以我的问题是,当我尝试向具有该类型的实体添加属性时NSBooleanAttributeType,它会有点错误.当我将它添加到我的NSManagedObject子类头文件(在教程中,那将是Run.h)as

@property (retain) BOOL *booleanProperty;
Run Code Online (Sandbox Code Playgroud)

编译失败,说error: property 'booleanProperty' with 'retain' attribute must be of object type.

似乎Cocoa中的某些地方使用NSNumber对象来表示布尔值,所以我尝试将其设置为

@property (retain) NSNumber *booleanProperty;
Run Code Online (Sandbox Code Playgroud)

代替.但是,这会引起以下运行时错误:

*** -[NSAttributeDescription _setManagedObjectModel:]: unrecognized selector sent to instance 0x101b470
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSAttributeDescription _setManagedObjectModel:]: unrecognized selector sent to instance 0x101b470'
Run Code Online (Sandbox Code Playgroud)

使用GDB,我能够将其追溯到我的源代码中的行,在那里我将我的实体添加到托管对象模型:

[DVManagedObjectModel setEntities:[NSArray arrayWithObjects:myEntityWithABooleanAttribute, myOtherEntity]];
Run Code Online (Sandbox Code Playgroud)

所以我的问题是:我应该在自定义类头中将booleanProperty设置为什么类型?

cocoa core-data objective-c

14
推荐指数
4
解决办法
2万
查看次数

标签 统计

cocoa ×1

core-data ×1

objective-c ×1