Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forcing Core Data to refresh an NSManagedObject from a previous stored version when an updated version is already in memory

Tags:

ios

core-data

I'm having trouble forcing Core Data to refresh some of my NSManagedObject subclasses in a document based iOS app I'm writing.

The problem is in dealing with the situation where the user loads a second document while there are unsaved changes in the current document At the moment, if the user loads the first document again, the unsaved changes show up. The documents are loaded using an NSFetchRequest for the document's root object. This fetch request has the property -setShouldRefreshRefetchedObjects: set to YES and the property -setIncludesPendingChanges: set to NO I'm certain that they aren't being saved to the persistent store, since terminating the app and restarting it causes the original unaltered document to show up. Also, I have SQL debug turned on, and it shows that the app isn't fetching from the relevant tables the second time around

like image 969
Rich Tolley Avatar asked Feb 01 '26 19:02

Rich Tolley


1 Answers

I know this question is already answered, but what about using method refreshObject:mergeChanges: of NSManagedObjectContext?

see NSManagedObject Class Reference refreshObject:mergeChanges:

like image 140
JakubKnejzlik Avatar answered Feb 03 '26 09:02

JakubKnejzlik