Created
December 30, 2012 05:02
-
-
Save sammcewan/4411085 to your computer and use it in GitHub Desktop.
This Gist will intertwine RK and MagicalRecord.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Initialize RestKit | |
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url]; | |
RKObjectManager *objectManager = [[RKObjectManager alloc] initWithHTTPClient:httpClient]; | |
[AFNetworkActivityIndicatorManager sharedManager].enabled = YES; | |
// Complete Core Data stack initialization | |
NSManagedObjectModel *managedObjectModel = [NSManagedObjectModel mergedModelFromBundles:nil]; | |
RKManagedObjectStore *managedObjectStore = [[RKManagedObjectStore alloc] initWithManagedObjectModel:managedObjectModel]; | |
objectManager.managedObjectStore = managedObjectStore; | |
// Invoke mappings method | |
[self setMappings:managedObjectStore objectManager:objectManager]; | |
NSString *databaseName = @"DBName.sqlite"; | |
[managedObjectStore createPersistentStoreCoordinator]; | |
NSString *storePath = [RKApplicationDataDirectory() stringByAppendingPathComponent:databaseName]; | |
NSError *error; | |
NSPersistentStore *persistentStore; | |
persistentStore = [managedObjectStore addSQLitePersistentStoreAtPath:storePath | |
fromSeedDatabaseAtPath:nil | |
withConfiguration:nil | |
options:nil | |
error:&error]; | |
[ [NSURLCache sharedURLCache] removeAllCachedResponses]; | |
[managedObjectStore createManagedObjectContexts]; | |
managedObjectStore.managedObjectCache = [[RKInMemoryManagedObjectCache alloc] initWithManagedObjectContext:managedObjectStore.persistentStoreManagedObjectContext]; | |
// Add to magical record | |
[NSManagedObjectContext MR_initializeDefaultContextWithCoordinator:managedObjectStore.persistentStoreCoordinator]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment