我有一个名为Filter的对象。 它有两个字段 - id(字符串)和title(字符串)。过滤器代表过滤衣服,有三种类型的过滤器 - 颜色,尺寸和品牌。我想让他们分开,因为现在他们到达同一个阵列。
这是我的代码:
[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。现在,当我得到映射结果时,我得到一个巨大的过滤器值数组,其中所有这些过滤器都来了。
我想为他们添加另一个属性,说明他们的来源,如颜色或品牌,但我如何根据我收到的关键路径分配给这个属性?
答案 0 :(得分:1)
不是从映射结果中取array
,而是取dictionary
。它包含响应描述符中的所有键路径作为键,映射对象数组作为值。
您需要使用字典中的键来更新对象,因为我认为映射元数据中的密钥路径不可用(尽管这值得检查)。