Skip to content

Instantly share code, notes, and snippets.

@atomicbird
Created January 30, 2012 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atomicbird/1706663 to your computer and use it in GitHub Desktop.
Save atomicbird/1706663 to your computer and use it in GitHub Desktop.
[theCreatingMOC performBlockAndWait:^{
// Insert some test data...
NSManagedObject *thePerson = [NSEntityDescription insertNewObjectForEntityForName:@"Person" inManagedObjectContext:theCreatingMOC];
[thePerson setValue:@"Steve Jobs" forKey:@"name"];
NSManagedObject *theCompany = [NSEntityDescription insertNewObjectForEntityForName:@"Company" inManagedObjectContext:theCreatingMOC];
[theCompany setValue:@"Apple" forKey:@"name"];
[theCompany setValue:[NSSet setWithObject:thePerson] forKey:@"employees"];
NSError *thePermanentIDError = nil;
[theCreatingMOC obtainPermanentIDsForObjects:[NSArray arrayWithObject:theCompany] error:&thePermanentIDError];
NSLog(@"Permanent ID error: %@", thePermanentIDError);
// And save it...
NSError *theError = NULL;
[theChildMOC save:&theError];
NSLog(@"MOC Saved (%@)", theError);
// Store a object URL so we can do our magic in whatever MOC we want...
theCompanyURL = theCompany.objectID.URIRepresentation;
NSLog(@"%@", theCompanyURL);
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment