我正在创建我的第一个 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 的键值编码。”