ios - 如何根据 RestKit 中的关键路径分离相似的实体映射?

标签 ios objective-c restkit

我有一个名为 Filter 的对象。 它有两个字段 - id(字符串)和 title(字符串)。 Filter 表示对衣服的过滤,有颜色、尺码和品牌三种滤镜。我想让它们分开,因为它们现在到达同一个数组。

这是我的代码:

[filtersMapping addAttributeMappingsFromDictionary:@{@"id": @"id_", @"title" : @"title"}];
filtersMapping.identificationAttributes = @[@"id_"];
[objectManager addResponseDescriptor:[RKResponseDescriptor responseDescriptorWithMapping:filtersMapping
                                                                             pathPattern:@"catalog/filter"
                                                                                 keyPath:@"size_values"
                                                                             statusCodes:statusCodes]];

[objectManager addResponseDescriptor:[RKResponseDescriptor responseDescriptorWithMapping:filtersMapping
                                                                             pathPattern:@"catalog/filter"
                                                                                 keyPath:@"brand_values"
                                                                             statusCodes:statusCodes]];

[objectManager addResponseDescriptor:[RKResponseDescriptor responseDescriptorWithMapping:filtersMapping
                                                                             pathPattern:@"catalog/filter"
                                                                                 keyPath:@"color_values"
                                                                             statusCodes:statusCodes]];

正如您从映射中看到的那样,我从服务器获得了三个数组。它们是 size_values、brand_values 和 color_values。现在,当我得到映射结果时,我会得到一个巨大的过滤器值数组,所有这些过滤器都来自这里。

我想给它们添加另一个属性来说明它们的来源,例如颜色或品牌,但是我如何根据我从中收到的关键路径分配给这个属性?

最佳答案

不是从映射结果中获取数组,而是获取字典。这包含来自响应描述符的所有键路径作为键,映射对象数组作为值。

您需要使用字典中的键来更新您的对象,因为我认为键路径在映射元数据中不可用(尽管这值得检查)。

关于ios - 如何根据 RestKit 中的关键路径分离相似的实体映射?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20719469/

相关文章:

ios - iphone模拟器只加载黑屏

ios - RestKit+CoreData+MagicalRecord : how not to persist managed objects

ios - AutoLayout UIScrollView 内容在旋转时不调整大小(包括示例项目)

iphone - 在 IOS 中通过 HTTP 流式传输视频

ios - UIPageViewController 与多个 UIViewController 与标题和底栏

ios - UITableViewHeader 的 UISearchBar subview ?

ios - 主线程上的 AFNetworking 和 NSURLConnection

google-analytics - Restkit和Google Analytics(分析)

ios - 重复符号 _OBJC_IVAR_$_GCOAuth.OAuthParameters ShareKit 和 RestKit。

ios - APNS : Sending the same notification more than once