1

我正在使用Mantle,它符合我的基本需求。在声明JSONKeyPathsByPropertyKey和 some之后PropertyJSONTransformer,我可以将 JSON Dictionary 转换为对象

ETPUser *user = [MTLJSONAdapter modelOfClass:[ETPUser class] fromJSONDictionary:jsonDict error:nil];

现在我想在这个转换过程中加入我的其他复杂字段(设置其他未在 中声明的属性JSONKeyPathsByPropertyKeyjsonDict,但找不到任何方法

如何钩入地幔?

4

1 回答 1

0

试试这个片段:

- (id)initWithDictionary:(NSDictionary *)dictionary error:(NSError *__autoreleasing *)error {

    NSDictionary *hookedValue = [[NSDictionary alloc] initWithObjectsAndKeys:
                                @"defaultValue1", @"defaultKey1",
                                @"defaultValue2", @"defaultKey2",
                                @"defaultValue3", @"defaultKey3",
                                nil];

    dictionary = [hookedValue mtl_dictionaryByAddingEntriesFromDictionary:dictionary];
    return [super initWithDictionary:dictionary error:error];
}
于 2015-09-24T08:33:31.880 回答