Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2010
445
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement