icodesign
icodesign

Reputation: 876

Change realm file without restarting app

I'm using realm with iCloud document, so question:

How can I change realm file without restarting app when iCloud document changes?

Upvotes: 0

Views: 346

Answers (1)

Der Ditsch
Der Ditsch

Reputation: 83

You should never change a Realm file while it is opened by a Realm object. This could end in unknown side effects.

So I would recommend to export the realm file whenever it makes sense. This file could be synced via iCloud and also be monitored for changes - to import the changes.

Exporting method explained the docs: https://realm.io/docs/swift/latest/api/Classes/Realm.html#/s:FC10RealmSwift5Realm15writeCopyToPathFS0_FTSS13encryptionKeyGSqCSo6NSData__GSqCSo7NSError_

If the realm file is larger there is another disadvantage: iCloud would always sync the whole file even for smaller changes.

In short: It feels complicated to implement a clean, conflict free syncing solution using Realm and iCloud. Maybe you should think about using CloudKit or any similar backend service to realize your data syncing: https://developer.apple.com/library/ios/documentation/DataManagement/Conceptual/CloudKitQuickStart/Introduction/Introduction.html

Upvotes: 4

Related Questions