I have an NSManagedObjectContext, i make a couple of changes to the model and then… to “commit” the transactions, what’s the difference between doing:
[context save:&error];
and
[context processPendingChanges];
It seems they both do the same thing.
In a nutshell,
processPendingChangeschanges the state of the current object graph.savewill save the current object graph to disk.Calling
savewill callprocessPendingChangesautomatically.If you think of a text file in a word processor,
saveis analogous to saving the document to disk.processPendingChangesis analogous to telling the word processor to update it’s internal state of the document after an edit, but without saving to disk. This usually triggers updates to the UI such as updating a displayed word or line count, doing any necessary formatting, etc…In my experience, for the iPhone, you rarely need
processPendingChanges.I believe it is mostly intended for Mac OS X and handling advanced or complicated undo management or updating UI bindings.For the iPhone, this is usually done to trigger NSFetchedResultsControllers to update table views. Even then, this is somewhat rare. If you aren’t sure just stick with
saveFor more info, go study the difference between
NSManagedObjectContextDidSaveNotificationandNSManagedObjectContextObjectsDidChangeNotificationin the docs.