Created
January 30, 2012 21:19
-
-
Save atomicbird/1706770 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
NSManagedObjectContext *theCreatingMOC = theChildMOC; | |
[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"]; | |
// And save it... | |
NSError *theError = NULL; | |
[theChildMOC save:&theError]; | |
NSLog(@"MOC Saved (%@)", theError); | |
// Save our main MOC (if the inserts happen in a child MOC, saving the child MOC bubbles the changes up the main MOC, so we now have to save the main MOC) | |
[theMainMOC performBlockAndWait:^{ | |
NSError *theError = NULL; | |
[theMainMOC 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