简体   繁体   English

iOS Swift Realm Sync问题

[英]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 for sync with 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 sync, it is saved locally. 我创建了一些没有同步的数据,它在本地保存。 However, if I turn on sync(different configuration), the previously created data(locally) is not synced to the server? 但是,如果我打开同步(不同的配置),先前创建的数据(本地)不会同步到服务器? How to sync already saved data? 如何同步已保存的数据?

Realms are uniquely referenced by one of three mutually exclusive Realm.Configuration properties: 领域由三个互斥的Realm.Configuration属性中的一个唯一引用:

  1. fileURL
  2. inMemoryIdentifier
  3. syncConfiguration

Realm configurations with any of these properties with different values will refer to separate Realms. 具有不同值的任何这些属性的域配置将引用单独的域。

So your initial Realm has a fileURL value (with nil for the other two properties), whereas your second Realm has a syncConfiguration value (with nil for the other two properties) so they refer to separate Realms. 因此,您的初始Realm具有fileURL值(其他两个属性为nil ),而您的第二个Realm具有syncConfiguration值(其他两个属性为nil ),因此它们引用单独的Realms。

If you wish to copy data from the first (local) Realm to the second (synced) Realm, you may do so using Realm's APIs for reading objects & creating objects just like you would for any other data. 如果您希望将数据从第一个(本地)Realm复制到第二个(同步的)Realm,您可以使用Realm的API来读取对象和创建对象,就像对待任何其他数据一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM