领域:模块'Realm没有名为'Configuration'的成员

时间:2016-09-01 16:34:48

标签: ios swift realm

我正在尝试使用最新的官方文档启用加密:

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

这是文档中的代码:

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)")
    }
  }
}

我在这一行收到编译错误:

  

let config = Realm.Configuration(encryptionKey:key)

     

模块'Realm没有名为'Configuration'的成员

我正在使用Realm 1.0.2

1 个答案:

答案 0 :(得分:5)

您需要import RealmSwift,而不是import Realmimport Realm为您提供了Objective-C API。