I am querying for a Client NSManagedObject via Core Data in my app and displaying the result in a simple details UIView pushed onto my UINavigationsController stack – nothing complex or out of the ordinary.
When I navigate back out of this details page for this Client object I am also checking for updates to my Clients in the background and if there are some I update my data store quietly in a background thread on a different managed object context. This is working and I see the changes to the data appear in my Core Data store via my SQLite Database Browser so I know the data has been updated.
The problem is when I navigate back to that same Client I will not see the changes unless I completely close my app or select a different Client and then go back to the one I know has changes. It seems the last Client object fetch request is being cached by my managed object context.
How do I prevent this from happening?
You need to register for
NSManagedObjectContextDidSaveNotificationpassing the backgroundNSManagedObjectContextas the object and then callmergeChangesFromContextDidSaveNotification:when the notification fires on yourNSManagedObjectContexton the main thread.This is specified in the Core Data Programming Guide: Concurrency with Core Data. And dont forget to refresh the data in your view (if it is a table view call
reloadData)