How to design classes for RKEntityMapping (to-Core-Data mapping)

99 views Asked by At

I'm working with RestKit in new project and now there are two classes. First class FirstClass has some properties and second class SecondClass has few properties. FirstClass has to-many relationship of SecondClass objects. Where should I manage mapping in application? What is the best design and way to solve it? Now in both classes are dictionaries of mapping for classes and in class where I make request these mappings are combined together in RKEntityMapping with relationship and there is created RKResponseDescriptor. How you manage mappings in classes?

In both classes I've got something like this:

+ (NSDictionary *)dictionaryForResponseMapping {
return @{@"username" : @"username",
         @"email" : @"email",
         @"password" : @"password",
         @"nick" : @"nick",
         @"location" : @"location"/*,
         @"characters": @"characters"*/};
}

But I don't think it's good way.

Is it better way to keep mappings in some singleton class and make accessors to it? I think it will be good for unit testing also.

Thank you in advance.

1

There are 1 answers

1
Alex Kurkin On

It seems it's really hard to manage it the way you described it here, because every time you make a change to your model, your .h/.m will be overwritten (if you generate them again from CoreData model file).

Your question already contains an opinionated "correct" answer. I would go with singleton class for all mappings and will create accessors for using mappings when building response descriptors. At the same time it's very easy to maintain all these mappings.