0
如果我尝试使用FileManager类删除文件,则会出现错误。Swift 3.0和iOS:如何在Swift中设置文件的删除权限
以下功能返回true,这意味着我需要设置删除权限属性。然而我在haven't找到了一个关于如何去做的例子。
func isDeletableFile(atPath path: String) -> Bool
任何帮助?
代码:
func fileManager(_ fileManager: FileManager, shouldRemoveItemAtPath path: String) -> Bool {
// print("Should remove invoked for path \(path)")
return true
}
func fileManager(_ fileManager: FileManager, shouldProceedAfterError error: Error, removingItemAt URL: URL) -> Bool {
//print("Should process")
return true
}
func deleteAllFiles(subPath : String) {
var url = Bundle.main.bundleURL
url = url.appendingPathComponent(subPath)
let fileManager = FileManager.default
fileManager.delegate = self
if let enumerator = fileManager.enumerator(at: url, includingPropertiesForKeys: nil) {
for file in enumerator {
let fileAsNSURL = file as! NSURL
print("")
print("Deleting: \(fileAsNSURL.absoluteString!)")
print("")
do {
// I would like to set the deletable permissions before checking this..
if (fileManager.isDeletableFile(atPath: fileAsNSURL.absoluteString!)){
try fileManager.removeItem(atPath: fileAsNSURL.absoluteString!)
}
else{
print("its not deletable")
}
}
catch let error {
print("file-delete-error:\n\(error) for path \(fileAsNSURL.absoluteString!)")
}
}
}
}
http://stackoverflow.com/questions/40642217/uiimagecontentsoffile-returning-nil-despite-file-existing-in-caches-directory/40643037?s=1|0.8206#40643037 –
谢谢!它确实有助于解决 – mm24