How can I use the Github Mantle to select a class of properties based on another property in the same class? (or in the worst case, another part of the JSON object).
For example, if I have an object like this:
{ "content": {"mention_text": "some text"}, "created_at": 1411750819000, "id": 600, "type": "mention" }
I want to make a transformer as follows:
+(NSValueTransformer *)contentJSONTransformer { return [MTLValueTransformer transformerWithBlock:^id(NSDictionary* contentDict) { return [MTLJSONAdapter modelOfClass:ETMentionActivityContent.class fromJSONDictionary:contentDict error:nil]; }]; }
But the dictionary passed to the transformer includes only part of the JSON content, so I don't have access to the type field. Is there any access to the rest of the facility? Or is it somehow based on the model class "content" on "type"?
Earlier I had to do such hacks:
+(NSValueTransformer *)contentJSONTransformer { return [MTLValueTransformer transformerWithBlock:^id(NSDictionary* contentDict) { if (contentDict[@"mention_text"]) { return [MTLJSONAdapter modelOfClass:ETMentionActivityContent.class fromJSONDictionary:contentDict error:nil]; } else { return [MTLJSONAdapter modelOfClass:ETActivityContent.class fromJSONDictionary:contentDict error:nil]; } }]; }
json ios objective-c github-mantle
pj4533
source share