NOTE: This answer is very old. See comments for full history. My recommendation has since changed and I no longer recommend using unassociated NSManagedObject
instances. My current recommendation is to use temporary child NSManagedObjectContext
instances.
Original Answer
The easiest way to do this is to create your NSManagedObject
instances without an associated NSManagedObjectContext
.
NSEntityDescription *entity = [NSEntityDescription entityForName:@"MyEntity" inManagedObjectContext:myMOC];
NSManagedObject *unassociatedObject = [[NSManagedObject alloc] initWithEntity:entity insertIntoManagedObjectContext:nil];
Then when you want to save it:
[myMOC insertObject:unassociatedObject];
NSError *error = nil;
if (![myMoc save:&error]) {
//Respond to the error
}