核心数据映射的内部不一致错误

时间:2011-08-01 19:11:38

标签: iphone objective-c ipad core-data

我收到以下错误:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Illegal container for relationship: value = (
    "<CVStar: 0x6a2e990> (entity: CVStar; id: 0x6a2e980 <x-coredata:///CVStar/t20E391D3-6FA6-4521-84FE-EAA9469E012029> ; data: {\n    \"date_created\" = \"1312050431.973905\";\n    message = nil;\n    user = \"0x6a2be10 <x-coredata:///CVLogin/t20E391D3-6FA6-4521-84FE-EAA9469E012030>\";\n})",
    "<CVStar: 0x6a2aca0> (entity: CVStar; id: 0x6a2b0d0 <x-coredata:///CVStar/t20E391D3-6FA6-4521-84FE-EAA9469E012031> ; data: {\n    \"date_created\" = \"1312011314.591517\";\n    message = nil;\n    user = \"0x6a36490 <x-coredata://B8EAEF54-AC90-46F0-B442-93077B937C3F/CVLogin/p28>\";\n})"
); relationship = "stars".'

关于如何调试这个的任何想法?我有一个CVMessage类,它有一个CVStar的NSArray ..我已经在CVMessage上建立了一个模型关系,作为一个到多个CVStar(一个CVMessage可以有很多CVStar)。但这不起作用,这怎么可能呢?

以下是一些代码:

@class CVLogin;
@class CVTopic;

@interface CVMessage : NSManagedObject {

}

@property (nonatomic, retain) NSNumber * date_created;
@property (nonatomic, retain) NSString * message;
@property (nonatomic, retain) NSNumber * mid;
@property (nonatomic, retain) CVLogin * creator;
@property (nonatomic, retain) NSArray * stars;
@property (nonatomic, retain) NSArray * embeds;
@property (nonatomic, retain) CVTopic * topic;
@property (nonatomic, assign) BOOL options;

@end

@interface CVStar : NSManagedObject {

}

@property (nonatomic, retain) NSNumber * date_created;
@property (nonatomic, retain) CVLogin * user;

@end

一些屏幕截图,如果它有帮助

enter image description here

1 个答案:

答案 0 :(得分:7)

NSManagedObjects不能将NSArray作为属性类型,因为Core Data不支持它。相反,使用NSSet,它应该描述一种关系。如果必须已订购数据,则添加描述对象顺序的属性。另外,请记住,Core Data不仅仅是持久存储,而且不是 SQL数据库。如果您不将事物视为行和列,而是将其视为对象,那么您将做得更好。