IOS Swift Realm sync issue

I used this configuration code for local storage.

var configuration = Realm.Configuration.defaultConfiguration configuration.encryptionKey = getKey() as Data 

I used this configuration code to synchronize with the server.

 let syncServerURL = URL(string: serverUrl + objectName!)! var configuration = Realm.Configuration.defaultConfiguration configuration.encryptionKey = getKey() as Data configuration.syncConfiguration = SyncConfiguration(user: SyncUser.current!, realmURL: syncServerURL) 

I create some data without synchronization, they are saved locally. However, if I turn on synchronization (various configuration), the previously created data (locally) does not synchronize with the server? How to synchronize already saved data?

+3
source share
1 answer

Realities uniquely refer to one of three mutually exclusive properties of Realm.Configuration :

  • fileURL
  • inMemoryIdentifier
  • syncConfiguration

Realm configurations with any of these properties with different meanings will relate to individual areas.

So, your original value is fileURL (with nil for the other two properties), while your second Kingdom has syncConfiguration (with nil for the other two properties), so they refer to separate Realms.

If you want to copy data from the first (local) Realm to the second (synchronized) Realm, you can do this using the Realm API for reading objects and creating objects in the same way as for any other data.

0
source

Source: https://habr.com/ru/post/1268085/


All Articles