I'm using Mantle and it fits my basic need. After declaring JSONKeyPathsByPropertyKey and some PropertyJSONTransformer, I can turn a JSON Dictionary to an object

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

Now I want to hook into this transformation process to do my other complex fields (setting other properties that are not declared in JSONKeyPathsByPropertyKey) in the jsonDict, but can't find any ways to do this

How to hook into Mantle ?

有帮助吗?

解决方案

Try with this snippet:

- (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];
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top