Roobiq / RBQFetchedResultsController

Drop-in replacement for NSFetchedResultsController backed by Realm.
MIT License
476 stars 70 forks source link

Object state not in sync in controllerDidChangeObject #76

Closed anohren closed 8 years ago

anohren commented 8 years ago

Hi,

I'm getting all the necessary notifications for updated objects in controllerDidChangeObject, but the updated property of the object is not in sync with what was written on my serial dispatch queue (for database operations).

If I do a try! Realm().refresh() in controllerDidChangeObject -- e.g. whenever the change type is Updated -- the problem goes away.

I might add that the same property is written to twice in quick succession in different tasks on the same serial queue, and that in controllerDidChangeObject the second write appears as if it were the first write. I currently keep strong references to all the realm objects in the FRC and I'm assuming they will be up-to-date in controllerDidChangeObject.

bigfish24 commented 8 years ago

@anohren you will need to manually refresh the objects because if the object is on a different thread, there is no guarantee that when the FRC is done that other thread will have received and responded to the refresh that was triggered by the commit on your serial queue.

Short answer your way of removing the problem is the correct way to ensure the object is up-to-date.