Undo changes to CoreData using the two-hook application ManagedObjectContext

I am working on an application where the user can edit some entries manually, but they can also be updated from the server.

For custom updates, I use UndoManager to allow the user to undo / confirm the change group. When the user goes into edit mode, I do:

//when edit mode is entered
[[self.contact.managedObjectContext undoManager] beginUndoGrouping];
//when edit mode is finished
[[self.contact.managedObjectContext undoManager] endUndoGrouping];

//depending on button that was pressed to end edit mode, either:
[[self.contact.managedObjectContext undoManager] undo];
//or
[[self.contact managedObjectContext] save:nil];

For automatic updates from the server (the object can be modified by the server) I use the parent MOC. The one above, which I use to control edit mode, is the parent. I create a child MOC and in the background change the data from the server. At the end of the process, I do:

 [self.moc.save:nil]; //save to local MOC
 [self.moc.parentContext.save:nil]; //save to main thread MOC (the one with undo)

, , , UNDO - , , .

:

  • , .
  • .

. , MOC, .

+3
2

, , , . , .

, . performBlock... .

, , .

.. removeAllActions.

0

- .

, , parent-child. , , , , . , . (.. ), , , .

. . Apple Earthquakes.

0

All Articles