[iOS][Realm sdk] How to compare value on realm object server and local

Hello everyone,

on my iOS apps, we already synced data from local to Realm object server and can update / fetch realtime from it.

I have a case:

  1. Device A, update value to 10 .

  2. Device A auto sync from local to Realm object server.

  3. Device B get latest value ( 10 ).

  4. Device B update value to 20 on local. BUT can not sync to Realm object server because has some error (ex: internet…) -> On Realm object server still 10 .

  5. Device A, update value from 10 to 100 . Sync to Realm object server successful -> value on server is 100.

  6. Back to Device B, still has some error like not connect internet => the value still is 20. User click to update value from 20 to 40 . Device B can save on local. Right now, the internet is stable -> Device B auto sync data to Realm object server -> The data on Realm object server was reseted from 100 to 40

This is a problem relate to internet but I think we totally has some other errors -> we cannot sync data to Realm object server.
So I want to compare the data between Realm object server and Local before sync to Realm object server or before save on local.
Currently I can not find any way to resolve it. Can you help me, please?