Restkit v0.20动态映射到NSDictionary

时间:2013-02-14 15:11:34

标签: ios restkit

在Restkit v0.10中,可以使用以下代码从https://stackoverflow.com/a/12057398/871459

完成到NSDictionary的映射。
RKObjectMapping* mapping = [RKDynamicObjectMapping dynamicMapping];
mapping.objectMappingForDataBlock = ^(id data) {
    NSDictionary* object = [data objectForKey: @"object"];
    NSArray* keys = [object allKeys];

    RKObjectMapping* dataMapping = [RKObjectMapping objectMapping];
    //Use the keys to define mapping
    return dataMapping;
};

在v0.20中,这已不再可能。如何在Restkit v0.20上实现相同的功能?

1 个答案:

答案 0 :(得分:0)

在0.20中,他们使用RKDynamicMapping而不是RKDynamicObjectMapping。我还没有测试过,但答案可能在这里:

RKDynamicMapping* dynamicMapping = [RKDynamicMapping new];    
[dynamicMapping setObjectMappingForRepresentationBlock:RKObjectMapping *^(id data) {
    NSDictionary* object = [data objectForKey: @"object"];
    NSArray* keys = [object allKeys];

    RKObjectMapping* dataMapping = [RKObjectMapping objectMapping];
    //Use the keys to define mapping
    return dataMapping;
}]; 

或者查看their tutorial for 0.20