我正在创建我的第一个RestKit应用程序。我正在尝试将to_many关系映射到核心数据。
演讲者JSON
{
id: 1,
session_ids: [1,87]
},
{
id: 2,
session_ids: [2,88]
},
映射
sessionEntitiyMapping = [RKEntityMapping mappingForEntityForName:@"Session" inManagedObjectStore:self.managedObjectStore];
[sessionEntitiyMapping addAttributeMappingsFromDictionary:@{
@"id": @"session_id",
}];
sessionEntitiyMapping.identificationAttributes = @[ @"session_id" ];
speakerEntityMapping = [RKEntityMapping mappingForEntityForName:@"Speaker" inManagedObjectStore:self.managedObjectStore];
[speakerEntityMapping addAttributeMappingsFromDictionary:@{
@"name": @"name",
@"id": @"speaker_id",
}];
[speakerEntityMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"session_ids"
toKeyPath:@"sessions"
withMapping:sessionEntitiyMapping]];
speakerEntityMapping.identificationAttributes = @[ @"speaker_id" ];
错误
由于未捕获的异常'NSUnknownKeyException'而终止应用程序,原因:'[< __ NSCFNumber 0x8569690> valueForUndefinedKey:]:此类不是密钥值编码兼容的密钥ID。'
答案 0 :(得分:0)
我认为问题在于您在模型中使用原语,即session_id具有NSInteger
类型。不幸的是,您不允许使用它,请改用NSNumber
。