快速复制文件 [英] Copy file with swift
本文介绍了快速复制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用此代码复制文件数据库
I am copying a file database with this code
try fileManager.copyItem(atPath: storeURL.path, toPath: storeCopyURL.path)
我可以看到创建了一个新的 sqlite 数据库
I can see that a new sqlite database is created
稍后,当我尝试使用此功能时
later, when I try to use this function
try! sharedInstance.managedObjectStore.addSQLitePersistentStore(atPath: storeURL.path, fromSeedDatabaseAtPath: storeCopyURL.path, withConfiguration: nil, options: nil)
出现错误
E restkit.core_data:RKManagedObjectStore.m:299 复制种子失败来自路径的数据库...
E restkit.core_data:RKManagedObjectStore.m:299 Failed to copy seed database from path ...
推荐答案
要安全地复制文件,您应该使用以下扩展名:
To securely copy a file you should use the following extension:
extension FileManager {
open func secureCopyItem(at srcURL: URL, to dstURL: URL) -> Bool {
do {
if FileManager.default.fileExists(atPath: dstURL.path) {
try FileManager.default.removeItem(at: dstURL)
}
try FileManager.default.copyItem(at: srcURL, to: dstURL)
} catch (let error) {
print("Cannot copy item at \(srcURL) to \(dstURL): \(error)")
return false
}
return true
}
}
有关 CoreData 的任何其他内容,我们需要有关您的代码以及您尝试执行的操作的更多信息.
For anything else regarding CoreData we need more information about your code and what you are trying to do.
这篇关于快速复制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文