Core Data中自引用关系的KVC合规性错误

时间:2014-04-19 20:42:53

标签: ios core-data key-value-coding

我在Core Data模型中有一个Person实体。我想在概念上创建一个“朋友”关系,这本质上是一种自引用关系(即期望朋友获取返回“Person”对象的列表。但是,没有设置反向关系。

我得到以下异常:

app[7713:90b] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Person 0xd55dd70> valueForUndefinedKey:]: the entity Person is not key value coding-compliant for the key "vprofiles".'

问题是,为什么这会导致错误,更不用说应用程序崩溃了?作为一个对象图,如果它具有共同的映射模式,那么它是否应该开箱即用?

该应用程序在此行崩溃:

NSArray *friends = [[person valueForKey:@"vprofiles"] allObjects];

我的Person界面生成如下。

@interface Person : NSManagedObject

@property (nonatomic, retain) NSDate * createdAt;
@property (nonatomic, retain) NSString * email;
@property (nonatomic, retain) NSDate * updatedAt;
@property (nonatomic, retain) NSString * username;
@property (nonatomic, retain) NSSet *vprofiles;
@end

@interface Person (CoreDataGeneratedAccessors)

- (void)addVprofilesObject:(Person *)value;
- (void)removeVprofilesObject:(Person *)value;
- (void)addVprofiles:(NSSet *)values;
- (void)removeVprofiles:(NSSet *)values;

@end

0 个答案:

没有答案