Delete specified file from document directory

前端 未结 10 951
礼貌的吻别
礼貌的吻别 2020-12-02 06:18

I want to delete an image from my app document directory. Code I have written to delete image is:

 -(void)removeImage:(NSString *)fileName
{
    fileManag         


        
10条回答
  •  隐瞒了意图╮
    2020-12-02 06:33

    You can double protect your file removal with NSFileManager.defaultManager().isDeletableFileAtPath(PathName) As of now you MUST use do{}catch{} as the old error methods no longer work. isDeletableFileAtPath() is not a "throws" (i.e. "public func removeItemAtPath(path: String) throws") so it does not need the do...catch

    let killFile = NSFileManager.defaultManager()
    
                if (killFile.isDeletableFileAtPath(PathName)){
    
    
                    do {
                      try killFile.removeItemAtPath(arrayDictionaryFilePath)
                    }
                    catch let error as NSError {
                        error.description
                    }
                }
    

提交回复
热议问题