difference between save: and processPendingChanges: in CoreData
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
[cont开发者_如何学运维ext processPendingChanges];
It seems they both do the same thing.
In a nutshell, processPendingChanges
changes the state of the current object graph. save
will save the current object graph to disk.
Calling save
will call processPendingChanges
automatically.
If you think of a text file in a word processor, save
is analogous to saving the document to disk.
processPendingChanges
is 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 save
For more info, go study the difference between NSManagedObjectContextDidSaveNotification
and NSManagedObjectContextObjectsDidChangeNotification
in the docs.
精彩评论