matthewcheok / Realm-JSON

A concise Mantle-like way of working with Realm and JSON.
MIT License
661 stars 129 forks source link

merging two field into one #91

Open ordinaryman09 opened 8 years ago

ordinaryman09 commented 8 years ago

hello,

is there any way to merge two field into one? for example, if the dictionary contains the following: { street 1 : "xxx", street 2 : "yyy" }

I want merge it to just "street" property.

thanks!

viktorasl commented 8 years ago

Hey. You can use static jsonPreprocessing: method and merge those fields before persisting the object

ordinaryman09 commented 8 years ago

Thank you. I check your code a little bit more and I noticed the selector you're looking for is preprocessedJSON not jsonPreprocessing. Also, I think it might be helpful for others if you update the ReadMe

+ (NSDictionary *)preprocessedJSON:(NSDictionary *)dictionary {
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithDictionary:dictionary];
    dict[@"releaseCount"] = @(0);
    return dict.copy;
}
viktorasl commented 8 years ago

Yes, sorry, the method is called preprocessedJSON:. PR is already made #93

ordinaryman09 commented 8 years ago

No worries. great work! Thanks brother.