我在 App Store 上有一个实时应用程序,它使用SQLite作为数据库,现在我想实现下一个更新Core Data,从 .sqlite 文件加载所有数据,而不破坏应用程序。我一直在阅读教程,但它并没有多大帮助。我不知道如何继续。请为我指出正确的方向。
\n我在iOS文档目录中存储了一个.jpg图像.我可以写文件和读取文件,但是当它要删除它们时它说没有这样的文件但是不能因为我可以用相同的URL读取它.
读:
let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
let path = NSURL(fileURLWithPath: paths[0] as String)
let fullPath = path.appendingPathComponent(info["pi"] as! String)
let data = NSData(contentsOf: fullPath!)
Run Code Online (Sandbox Code Playgroud)
删除:
let fileManager = FileManager.default
fileManager.delegate = self
let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
let path = NSURL(fileURLWithPath: paths[0] as String)
let fullPath = path.appendingPathComponent(info["pi"] as! String)
do {
try fileManager.removeItem(atPath: "\(fullPath!)")
} catch {
print("\(error)")
}
Run Code Online (Sandbox Code Playgroud)
它抛出:
Error Domain=NSCocoaErrorDomain Code=4 "“image_496251232.806566.jpg” couldn’t be removed." UserInfo={NSUnderlyingError=0x1758eb40 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}, …Run Code Online (Sandbox Code Playgroud)