ff10
ff10

Reputation: 3147

Core Data: Update an NSManagedObject with the option to fall back to it's original state

Consider a managed object with a set of properties A which have to be replaced with a set of properties B. However, the mechanism to retrieve the information for B is not fail-safe (e.g. if there is a failing network connection) and there is a chance that B cannot be fully constructed. In this case, I need to fall back to the state of object A to maintain consistency.
What is the best Core Data pattern to realize a fail safe, consistent update mechanism in this case?

Upvotes: 0

Views: 171

Answers (1)

drew
drew

Reputation: 2371

Until you send the save: selector to the NSManagedObjectContext object, none of your changes are persisted. Once 'saved' you have created a 'commit point'. If you want to roll back any changes you have made since the last commit point in core data send the rollback selector to your NSManagedObjectContext. You will need to check for successful outcome of your network activity and send either save: or rollback depending on the final outcome.

Upvotes: 1

Related Questions