У меня есть проект, над которым я работаю, что сохраняет данные в PDF. Код для этого:iOS: удалить файл в .DocumentDirectory с помощью Swift2
// 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
}
}
Я пытался найти ответ в Интернете, но не могу найти что-нибудь для Swift 2. Может кто-то пожалуйста, помогите?
Я пытался работать с этим, но не повезло:
var fileManager:NSFileManager = NSFileManager.defaultManager()
var error:NSErrorPointer = NSErrorPointer()
fileManager.removeItemAtPath(filePath, error: error)
Я просто хочу, чтобы удалить конкретный элемент прокатывается и не все данные в DocumentDirectory
.
Спасибо. Я ценю это. Я немного поправился, чтобы работать с моим проектом. – ChallengerGuy