문제

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