我正在学习如何捆绑一个领域文件的领域文档。我已经成功地将所有必要的数据加载到我的加密文件中,但我似乎无法压缩该文件并将其移到其他地方。
代码
// AppDelegate
fileprivate func compactRealm() {
if let realmPath = Realm.Configuration.defaultConfiguration.fileURL {
let destination = realmPath.deletingLastPathComponent().appendingPathComponent("compact.realm")
if FileManager.default.fileExists(atPath: realmPath.path) {
do {
// let encryption = Constants.key.data(using: String.Encoding.utf8)
try Realm().writeCopy(toFile: destination)
print("File normally compressed !")
} catch {
fatalError(error.localizedDescription)
}
} else {
print("Realm file does not exist")
// fatalError()
}
}
}
结果
“错误Domain=io.realm Code=2”无法打开路径Code=2处的领域,而不是领域文件。NSFilePath=/var/mobile/Containers/Data/Application/B4D487F8-5AEC-4906-B989-7DB953095A35/Documents/default.realm,{Error Code=2,UserInfo= Underlying=Not一个领域文件,NSLocalizedDescription=Unable打开一个领域路径'/var/mobile/Containers/Data/Application/B4D487F8-5AEC-4906-B989-7DB953095A35/Documents/default.realm':而不是一个领域文件。}
我已经检查过了:领域文件确实存在!
顺便说一句,我对未加密的文件尝试过相同的代码,所以我不知道它对加密的领域文件不起作用!
https://stackoverflow.com/questions/49297592
复制