我正在使用此代码复制文件数据库
try fileManager.copyItem(atPath: storeURL.path, toPath: storeCopyURL.path)
Run Code Online (Sandbox Code Playgroud)
我可以看到创建了一个新的sqlite数据库
以后,当我尝试使用此功能时
try! sharedInstance.managedObjectStore.addSQLitePersistentStore(atPath: storeURL.path, fromSeedDatabaseAtPath: storeCopyURL.path, withConfiguration: nil, options: nil)
Run Code Online (Sandbox Code Playgroud)
我得到一个错误
E restkit.core_data:RKManagedObjectStore.m:299无法从路径复制种子数据库...
要安全地复制文件,您应该使用以下扩展名:
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
}
}
Run Code Online (Sandbox Code Playgroud)
关于CoreData的其他任何信息,我们需要有关您的代码以及您要执行的操作的更多信息。
| 归档时间: |
|
| 查看次数: |
2900 次 |
| 最近记录: |