Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Wrap your changes in a <code>NSUndoManager beginUndoGrouping</code> and then a <code>NSUndoManager endUndoGrouping</code> followed by a <code>NSUndoManager undo</code>.</p> <p>That is the correct way to roll back changes. The <code>NSManagedObjectContext</code> has its own internal <code>NSUndoManager</code> that you can access.</p> <h2>Update showing example</h2> <p>Because the <code>NSUndoManager</code> is nil by default on Cocoa Touch, you have to create one <strong>and set it into the <code>NSManagedObjectContext first</code></strong>.</p> <pre><code>//Do this once per MOC NSManagedObjectContext *moc = [self managedObjectContext]; NSUndoManager *undoManager = [[NSUndoManager alloc] init]; [moc setUndoManager:undoManager]; [undoManager release], undoManager = nil; //Example of a grouped undo undoManager = [moc undoManager]; NSManagedObject *test = [NSEntityDescription insertNewObjectForEntityForName:@"Parent" inManagedObjectContext:moc]; [undoManager beginUndoGrouping]; [test setValue:@"Test" forKey:@"name"]; NSLog(@"%s Name after set: %@", __PRETTY_FUNCTION__, [test valueForKey:@"name"]); [undoManager endUndoGrouping]; [undoManager undo]; NSLog(@"%s Name after undo: %@", __PRETTY_FUNCTION__, [test valueForKey:@"name"]); </code></pre> <p>Also make sure that your accessors are following the rules of KVO and posting <code>-willChange:</code>, <code>-didChange:</code>, <code>-willAccess:</code> and <code>-DidAccess:</code> notifications. If you are just using <code>@dynamic</code> accessors then you will be fine.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload