etayluz
etayluz

Reputation: 16436

Realm: Module 'Realm has no member named 'Configuration'

I am trying to enable encryption with realm using the latest official documentation:

https://realm.io/docs/swift/latest/#encryption

This is the code from the documentation:

import Foundation
import Realm

class TestRealm:NSObject {

  func test() {
    // Generate a random encryption key
    let key = NSMutableData(length: 64)!
    SecRandomCopyBytes(kSecRandomDefault, key.length,
                       UnsafeMutablePointer<UInt8>(key.mutableBytes))

    // Open the encrypted Realm file
    let config = Realm.Configuration(encryptionKey: key)
    do {
      let realm = try Realm(configuration: config)
      // Use the Realm as normal
    } catch let error as NSError {
      // If the encryption key is wrong, `error` will say that it's an invalid database
      fatalError("Error opening realm: \(error)")
    }
  }
}

I am receiving a compilation error on this line:

let config = Realm.Configuration(encryptionKey: key)

Module 'Realm has no member named 'Configuration'

I am using Realm 1.0.2

Upvotes: 1

Views: 1364

Answers (1)

Thomas Goyne
Thomas Goyne

Reputation: 8138

You need import RealmSwift, not import Realm. import Realm gives you the Objective-C API.

Upvotes: 6

Related Questions