我在以下堆栈跟踪中经常看到此崩溃日志。
致命错误:创建领域实例时出错:Domain = io.realm代码= 2错误“无法在路径'/ var / mobile / Containers / Data / Application / 89360B70-5136-4CAF-9392-5B390784CBF3 / Documents / slcsp.realm.lock':open()失败:不允许操作。” UserInfo = {错误代码= 2,
public var realm: Realm {
var config = Realm.Configuration.defaultConfiguration
if config.inMemoryIdentifier == nil {
guard let docDirectory = FileManager.documentDirectory() else {
fatalError("Couldn't get user document directory")
}
if FileManager.default.fileExists(atPath: docDirectory.path) == false {
try? FileManager.default.createDirectory(at: docDirectory, withIntermediateDirectories: true)
}
let dbFilename = "blah.realm"
config.fileURL = docDirectory.appendingPathComponent(dbFilename)
}
do {
return try Realm(configuration: config)
} catch let error as NSError {
fatalError("Error creating realm instance: \(error)")
}
}
我一直在尝试自己复制该文件,但无法找到方法,也不确定是什么原因造成的。