Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. - (void)requestDidFinishLoad:(TTURLRequest*)request {
  2.    ...
  3.    ... //read your JSON into a NSDictionary
  4.  
  5.    NSManagedObjectContent* context = appDelegate.managedObjectContext;
  6.    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  7.    for (NSDictionary* itemInfo in jsonItems) {
  8.       DBResource *resource = (DBResource*)[NSEntityDescription insertNewObjectForEntityForName:@"MyEntity" inManagedObjectContext:context];
  9.       resource.id = [itemInfo valueForKey:@"id"];
  10.       resource.name = [itemInfo valueForKey:@"name"];
  11.    }
  12.    NSError *error;
  13.    if( ![context save:&error] ) {
  14.       // handle error
  15.    }
  16.  
  17.    [context reset];
  18.    [pool drain];
  19.    ... // other cleanup
  20. }