iOS Swift Realm Sync问题 [英] iOS Swift Realm Sync Issue

查看:102
本文介绍了iOS Swift Realm Sync问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将此配置代码用于本地存储.

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?

推荐答案

领域是由三个互斥的Realm.Configuration属性之一唯一引用的:

Realms are uniquely referenced by one of three mutually exclusive Realm.Configuration properties:

  1. fileURL
  2. inMemoryIdentifier
  3. syncConfiguration
  1. fileURL
  2. inMemoryIdentifier
  3. syncConfiguration

具有这些属性的 any 且具有不同值的

Realm配置将引用单独的Realms.

Realm configurations with any of these properties with different values will refer to separate Realms.

因此,您的初始Realm具有fileURL值(其他两个属性带有nil),而第二个Realm具有syncConfiguration值(其他两个属性带有nil),因此它们引用单独的领域.

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复制到第二个(同步)Realm,则可以使用Realm的API读取对象&创建对象就像处理其他数据一样.

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.

这篇关于iOS Swift Realm Sync问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆