I am copying a file database with this code
try fileManager.copyItem(atPath: storeURL.path, toPath: storeCopyURL.path)
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)
I get an error
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
}
}
For anything else regarding CoreData we need more information about your code and what you are trying to do.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With