Skip to content

Instantly share code, notes, and snippets.

@MrMaksimize
Created September 6, 2012 04:32
Show Gist options
  • Save MrMaksimize/3651262 to your computer and use it in GitHub Desktop.
Save MrMaksimize/3651262 to your computer and use it in GitHub Desktop.

https://github.com/AFNetworking/AFIncrementalStore

##Accessing an API using CoreData's NSIncrementalStore https://gist.github.com/1860108 http://sealedabstract.com/code/nsincrementalstore-the-future-of-web-services-in-ios-mac-os-x/

##AppDelegate.m

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
    if (__persistentStoreCoordinator != nil)
    {
        return __persistentStoreCoordinator;
    }
    
    __persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
  
  AFIncrementalStore *incrementalStore = (AFIncrementalStore *)[__persistentStoreCoordinator addPersistentStoreWithType:[APIOSIncrementalStore type] configuration:nil URL:nil options:nil error:nil];
  
  NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"APCI.sqlite"];

    NSError *error = nil;
    
    
  if (![incrementalStore.backingPersistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {
    NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
    abort();
  }
  
  NSLog(@"SQLite URL: %@", [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"APCI.sqlite"]);
  
    
    return __persistentStoreCoordinator;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment