Realm-JSON icon indicating copy to clipboard operation
Realm-JSON copied to clipboard

merging two field into one

Open ordinaryman09 opened this issue 9 years ago • 4 comments

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!

ordinaryman09 avatar Jun 18 '16 19:06 ordinaryman09

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

viktorasl avatar Jun 21 '16 20:06 viktorasl

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

ordinaryman09 avatar Jun 21 '16 20:06 ordinaryman09

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

viktorasl avatar Jun 21 '16 21:06 viktorasl

No worries. great work! Thanks brother.

ordinaryman09 avatar Jun 21 '16 21:06 ordinaryman09