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];
}