ndg
ndg

Reputation: 2645

Reverting CoreData data

I have an NSTableView which is populated via a CoreData-backed NSArrayController. Users are able to edit any field they choose within the NSTableView. When they select the rows that they have modified and press a button, the data is sent to a third-party webservice. Provided the webservice accepts the updated values, I want to commit those values to my persistent store. If, however, the webservice returns an error (or simply fails to return), I want the edited fields to revert to their original values.

To complicate matters, I have a number of other editable controls, backed by CoreData, which do not need to resort to this behaviour.

I believe the solution to this problem revolves around the creation of a secondary Managed Object context, which I would use only for values edited within that particular NSTableView. But I'm confused as to how the two MOC would interact with each other.

What's the best solution to this problem?

Upvotes: 0

Views: 414

Answers (1)

TechZen
TechZen

Reputation: 64428

The easiest solution would be to implement Core Data's undo functionality. That way you make the changes to Core Data but if the server returns the error, you just rollback the changes. See the Core Data docs for details.

Upvotes: 1

Related Questions