Skip to content

Instantly share code, notes, and snippets.

@jlee42
Created December 6, 2012 16:41
Show Gist options
  • Save jlee42/4225904 to your computer and use it in GitHub Desktop.
Save jlee42/4225904 to your computer and use it in GitHub Desktop.
// Set up RestKit Logging
RKLogConfigureByName("RestKit", RKLogLevelTrace);
RKLogConfigureByName("RestKit/Network*", RKLogLevelTrace);
RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelTrace);
// Initialize RestKit
NSURL *baseURL = [NSURL URLWithString:[[NSUserDefaults standardUserDefaults] valueForKey:@"application_base_url"]];
RKObjectManager *objectManager = [RKObjectManager managerWithBaseURL:baseURL];
// Enable Activity Indicator Spinner
[AFNetworkActivityIndicatorManager sharedManager].enabled = YES;
// Initialize managed object store
NSManagedObjectModel *managedObjectModel = [NSManagedObjectModel mergedModelFromBundles:nil];
RKManagedObjectStore *managedObjectStore = [[RKManagedObjectStore alloc] initWithManagedObjectModel:managedObjectModel];
objectManager.managedObjectStore = managedObjectStore;
[managedObjectStore createManagedObjectContexts];
// Setup our object mappings
/**
Mapping by entity. Here we are configuring a mapping by targetting a Core Data entity with a specific
name. This allows us to map back Twitter user objects directly onto NSManagedObject instances --
there is no backing model class!
*/
RKEntityMapping *userMapping = [RKEntityMapping mappingForEntityForName:@"User" inManagedObjectStore:managedObjectStore];
userMapping.identificationAttributes = @[ @"userID" ];
userMapping.setNilForMissingRelationships = YES;
userMapping.setDefaultValueForMissingAttributes = YES;
[userMapping addAttributeMappingsFromDictionary:@{
@"id": @"userID",
@"full_name": @"fullName",
@"display_name": @"displayName",
@"username": @"username",
@"lsuid": @"userLSUID",
@"photo_hash": @"photoHash",
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment