I often end up fetching arrays of objects from a backend and storing them into realm.
When fetching the list from the backend server to update the realm db it can happen that some objects have been modified and some have been removed from the server:
The modified objects are recognized by their primary key and automatically updated by realm when using copyToRealmorUpdate().
The removed objects are instead left as-is in the realm db and I have no means to understand that there's now stale data in the realm.
The first thing that came to my mind is to delete all the objects of that type from realm before the update. But this will lead to a poor UX because the objects themselves are usually data bound to a scroll view in the app's UI (so the user will see the scroll view becoming empty and then full again).
The second thing would be to check (using their primary key) which objects present in the realm DB are missing from the server's update list and remove them one by one.
I'm feeling both of these approaches are suboptimal, is there a better way to handle this?
Thanks, Bye, Marco