我有一個項目正在將數據保存到PDF中。這個代碼是:iOS:使用Swift2刪除.DocumentDirectory中的文件
// Save PDF Data
let recipeItemName = nameTextField.text
let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0]
pdfData.writeToFile("\(documentsPath)/\(recipeFileName).pdf", atomically: true)
我可以在一個單獨的UITableView
我在另一個ViewController
查看文件。當用戶滑動UITableViewCell
我希望它也從.DocumentDirectory
刪除項目。我爲UITableView
刪除代碼是:
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == .Delete {
// Delete the row from the data source
savedPDFFiles.removeAtIndex(indexPath.row)
// Delete actual row
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
// Deletion code for deleting from .DocumentDirectory here???
} else if editingStyle == .Insert {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
我試着在網上找到了答案,但無法找到斯威夫特2.任何人可以幫?
我試過這個,但沒有運氣的工作:
var fileManager:NSFileManager = NSFileManager.defaultManager()
var error:NSErrorPointer = NSErrorPointer()
fileManager.removeItemAtPath(filePath, error: error)
我只是想刪除特定項目刷卡,並在DocumentDirectory
並不是所有的數據。
謝謝。我很感激。我調整了一下,與我的項目合作。 – ChallengerGuy