Store but not save NSManagedObject in CoreData?

I have a short installation process in my application and I create an NSManagedObject to store the name and other details of an individual, however during this setup I don’t want to save the object until the user clicks β€œFinish” right at the end of the installation (just turn them off for any reason).

So, is it possible to hold an object that stores my information for a short time until the end of the installation process without actually saving it in CoreData?

Thanks.

+5
source share
2 answers

When you are dealing with CoreData, all add / modify / delete actions happen in NSManagedObjectContext, but the changes are not saved to disk until you call save in this context.

So, the answer is yes - this is the behavior that you should already receive. If you add or modify the properties of NSManagedObjects, these changes are saved in the context memory, but not saved to disk until you actually call save.

+2
source

You can also use

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

to create a managed entity without inserting it into your context. You can do this later by calling [managedObjectContext insertObject:obj]; .

+12
source

Source: https://habr.com/ru/post/913272/


All Articles