【问题标题】:RestKit mapping for specific entity特定实体的 RestKit 映射
【发布时间】:2013-10-28 13:11:58
【问题描述】:

我已经使用了用于不同实体映射的通用 RKObjectManager,如下面的 cod,但是当我尝试为特定实体进行映射时无法进行,因为我有两个具有相同 keyPath 的实体,这是我怎么能想到的问题。

   // Search  mapping ...
RKEntityMapping *searchEntityMapping = [RKEntityMapping mappingForEntityForName:NSStringFromClass([ABB class]) inManagedObjectStore: aBBManager.managedObjectStore];

[searchInfoEntityMapping addAttributeMappingsFromDictionary:@{
 @"count" : @"count",
 @"total_count" : @"totalCount",

 }];


 // Search Advanced  mapping ...
RKEntityMapping *searchAdvEntityMapping = [RKEntityMapping mappingForEntityForName:NSStringFromClass([ABB class]) inManagedObjectStore: aBBManager.managedObjectStore];

[searchAdvEntityMapping addAttributeMappingsFromDictionary:@{
 @"count" : @"count",
 @"data" : @"dataCount",

 }];

// Search  Descriptor
RKResponseDescriptor *aBBResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:searchEntityMapping pathPattern:nil keyPath:@"locations" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];


 // Search Adv Descriptor
 RKResponseDescriptor *aBB2ResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:searchAdvEntityMapping pathPattern:nil keyPath:@"locations" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

【问题讨论】:

    标签: ios json restkit restkit-0.20


    【解决方案1】:

    您应该使用pathPattern 参数来允许RestKit 在您发出特定请求时知道使用哪个响应描述符(因为您应该在URL 中为不同的实体使用不同的路径)。

    如果由于某种原因不能,您需要创建多个 RKObjectManager 实例,并为您提出的每个不同请求使用适当的实例。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-25
      • 2017-10-13
      • 1970-01-01
      • 1970-01-01
      • 2013-03-04
      • 2023-04-02
      • 1970-01-01
      • 2013-04-03
      相关资源
      最近更新 更多