I\'m using RestKit for a project and i noticed that there is no longer a method in the class that you can control all mappings in (elementToPropertyMappings), i therefore wonder
I think the domain model should be the only one who should know about the mapping. Here is how I map some flickr json:
I call the mappings when you need them (Can be in AppDelegate or where ever you want)
// Setup our object mappings
RKObjectMapping *photoMapping = [Photo mapWithMapping:nil];
RKObjectMapping *photosMapping = [Photos mapWithMapping:photoMapping];
And this is one of my domain objects: It contains the classMethod doing the mapping.
#import "Photos.h"
@implementation Photos
+ (RKObjectMapping*)mapWithMapping: (RKObjectMapping*)aMapping
{
RKObjectManager *objectManager = [RKObjectManager sharedManager];
RKManagedObjectMapping *mapping = [RKManagedObjectMapping mappingForClass:[self class] inManagedObjectStore:objectManager.objectStore];
[mapping mapKeyPathsToAttributes:
@"page", @"page",
@"pages", @"pages",
@"perpage", @"perpage",
@"stat", @"stat",
@"total", @"total",
nil];
if (aMapping) {
[mapping mapRelationship:@"photo" withMapping:aMapping];
}
return mapping;
}
@end
There are a few good ways to organize your mappings currently recommended:
The problem with defining mappings on a class method is that when you have relationships, you can wind up with circular dependencies as there's no ivars available to store the instances. We may be able to do something with blocks to help alleviate this problem, but no such work has been done yet.
I typically create a private method in my App Delegate that I call during app setup which sets up the RKObjectManager and then constructs all the mappings I use throughout the app. I believe the RestKit sample projects use this same pattern, so definitely check those out as a reference.