【问题标题】:restkit: mapping to_many relations with core datarestkit:映射 to_many 与核心数据的关系
【发布时间】:2013-07-06 20:37:26
【问题描述】:

我正在创建我的第一个 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> valueForUndefinedKey:]:此类不符合键 ID 的键值编码。”

【问题讨论】:

  • 您好!我正在尝试在我的应用程序中使用 restkit 并遇到同样的问题。您是否设法找到解决问题的方法?如果有,可以分享一下吗?

标签: iphone ios core-data restkit-0.20


【解决方案1】:

我认为问题在于您在模型中使用了原语,即 session_id 具有 NSInteger 类型。很遗憾,您不能使用它,请改用NSNumber

【讨论】:

  • 我已经从 xcode 生成了我所有的模型。它们都没有 NSInteger。
  • 请输入 RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelTrace);在项目的某个地方,让我们看看输出
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-23
  • 2013-08-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多