I have this code:
Store* store = [NSEntityDescription insertNewObjectForEntityForName:@"Store"];
store.name = @"My Company"
...
Now the store is managed in the context and will be saved when the context is saved, but I have a button where the user can cancel the form where data is collected. How do I undo or remove this from the context? Or am I thinking wrong?
Core Data uses a schema called a managed object model — an instance of NSManagedObjectModel . In general, the richer the model, the better Core Data is able to support your application. A managed object model allows Core Data to map from records in a persistent store to managed objects that you use in your application.
A managed object context is an instance of NSManagedObjectContext . Its primary responsibility is to manage a collection of managed objects. These managed objects represent an internally consistent view of one or more persistent stores.
A description of search criteria used to retrieve data from a persistent store.
Core Data has built-in support for undo, so you can undo individual changes by sending the -undo
message to the context:
[store.managedObjectContext undo];
It also supports -redo
. You can undo all changes up to the most recent save using the -rollback
method:
[store.managedObjectContext rollback]
as indicated in @melsam's answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With