Search code examples
iosswiftrealm

iOS Swift Realm Encryption and Sync with server


I used this configuration code for Realm Encryption

let configuration = Realm.Configuration(encryptionKey: "key" as Data)

let realm = try! Realm(configuration: configuration)

I used this configuration code for Realm Sync with server

let configuration = Realm.Configuration(syncConfiguration: SyncConfiguration(user: user, realmURL: syncServerURL))

let realm = try! Realm(configuration: configuration)

How we can do both Encryption and Sync with server using Realm?


Solution

  • The Realm.Configuration initializer can accept multiple arguments if you'd like to specify multiple aspects of the configuration:

    let config = Realm.Configuration(syncConfiguration: SyncConfiguration(user: user, realmURL: syncServerURL),
                                     encryptionKey: theKey)