Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Store But Don't Save NSManagedObject to CoreData?

I have a short setup process in my app and I create an NSManagedObject to store name and other details of an individual, however during this setup I don't want to save the object until the user presses 'Done' right at the end of the setup (just incase they cancel the setup for whatever reason).

So is it possible to keep hold the object holding my info for a short time until the end of the setup process without actually saving it into CoreData?

like image 919
Josh Kahane Avatar asked Apr 15 '12 18:04

Josh Kahane


2 Answers

You can also use

NSEntityDescription *ed = [NSEntityDescription entityForName:@"YourManagedObject" inManagedObjectContext:managedObjectContext];
YourManagedObject *obj = [[[YourManagedObject alloc] initWithEntity:ed insertIntoManagedObjectContext:nil] autorelease];

to create the managed object without inserting it into your context. You can do that later by calling [managedObjectContext insertObject:obj];.

like image 176
Christian Schnorr Avatar answered Sep 28 '22 07:09

Christian Schnorr


When you are dealing with CoreData, all add/modify/delete actions occur in the NSManagedObjectContext - but changes are not persisted to disk until you call 'save' on that context.

So the answer is yes - this is the behavior you should already be getting. If you are adding or modifying the properties of NSManagedObjects, these changes are kept in the memory of the context, but are not being saved to disk until you actually call 'save'.

like image 27
isaac Avatar answered Sep 28 '22 08:09

isaac