Where to place object mappings (in RestKIt)

Since I don't want to capture another thread, my question is about mappings.

Read first: Where is the best place to place object mappings in RestKit

I am sure that the answer that Blake Waters gave is likely to be very correct, since it is much smarter and more experienced than me, but for me the logic tells me to put a mapping in each model: if you change something in your model you just scroll away to change your mappings.

In my AppDelegate, I would just call initMappings (or whatever you want to name) in each of my models.

+6
mapping objective-c restkit
source share
3 answers

I am also a fan of posting comparisons with my models. I do this by adding a class method to each model so that I can get a mapping whenever I need it.

+ (RKObjectMapping *)objectMapping { RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[self class]]; [mapping mapKeyPath:@"Id" toAttribute:@"id"]; [mapping mapKeyPath:@"Subject" toAttribute:@"subject"]; [mapping mapKeyPath:@"Message" toAttribute:@"message"]; [mapping mapKeyPath:@"PostDate" toAttribute:@"postDateStr"]; [mapping mapKeyPath:@"StatusId" toAttribute:@"statusId"]; [mapping mapKeyPath:@"StatusDate" toAttribute:@"statusDateStr"]; mapping.setNilForMissingRelationships = YES; return mapping; } 
+1
source share

I chose the path to create the category and placed it there. I only created it in my delegate class than the mapping provider.

I think that the problem with its use in models is similar to the description in another thread, if you have a relationship, you can get circular links.

0
source share

I think itโ€™s very natural to think the way you do it makes sense, because you have more control over the code and it is cleaner, but you have to be very careful, as many said, the problem with circular links can be a big problem.

The solution to this problem is that when you have an object A related to B, and B - A, then in one of the two objects you will have to choose not to display the object directly, otherwise you will end the cycle.

When you have everything in one area, the definition of circular links becomes impossible because you need the original definition of B to add a link to A, so the solution I just mentioned is a natural way to do this with this approach.

It is up to you and your application, the approach you want to use, which is best for you and your team. You must choose between possible errors and clean code.

0
source share

All Articles