【问题标题】:RKObjectMapping connectionsRKObjectMapping 连接
【发布时间】:2013-11-19 07:50:35
【问题描述】:

我没有回应:

{
  "orders": [
    {
      "date": "2013-11-18T13:00:39.000Z",
      "state": "new",
      "id": 11,
      "order_item_ids": [
        27,
        28
      ]
    }
  ],
  "order_items": [
    {
      "count": 2,
      "id": 27,
      "item_id": 1,
      "order_id": 11
    },
    {
      "count": 1,
      "id": 28,
      "item_id": 2,
      "order_id": 11
    }
  ]
}

我想映射下一个对象:

@interface Order : NSObject
@property (nonatomic, strong) NSString* state;
@property (nonatomic, strong) NSMutableArray* orderItems;
@property (nonatomic, strong) NSDate* visitDate;
@end

orderItems 应该是以下数组:

@interface OrderItem : NSObject
@property (nonatomic) NSUInteger ID;
@property (nonatomic) NSUInteger itemID;
@property (nonatomic) NSUInteger count;
@end

如果是RKEntityMapping,我应该使用addConnectionForRelationship 通过order_items 响应将order_item_ids 映射到orderItems 数组。但是如果是RKObjectMapping,我应该怎么做才能连接它?当然,我可以使用单独的响应描述符映射订单和订单项,然后解析它,但我想让 RestKit 为我做这件事。另一个想法是使用 CoreData 和 RKEntityMapping 但我不确定在这种情况下我是否想要,在这种情况下会有点过分。

【问题讨论】:

    标签: ios restkit


    【解决方案1】:

    你不能用RKObjectMapping 自动完成它,因为你不能以任何方式索引到这两个数组。实体映射仅起作用,因为您可以在执行两个映射后使用外键映射。您可以通过使用多个响应描述符和映射然后组合映射结果的内容来复制它。

    【讨论】:

      猜你喜欢
      • 2011-12-22
      • 1970-01-01
      • 1970-01-01
      • 2014-02-08
      • 1970-01-01
      • 1970-01-01
      • 2023-03-22
      • 2013-07-03
      • 2012-04-30
      相关资源
      最近更新 更多