0

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

4

1 回答 1

0

我认为问题在于您在模型中使用了原语,即 session_id 具有NSInteger类型。不幸的是,您不允许使用它,请改用它NSNumber

于 2013-07-07T02:19:37.473 回答