//добавляю действие удаления для ячейки
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == .Delete {
let itemToDelete = items.count![indexPath.row] as! UITableView
NSManagedObjectContext.deleteObject(itemToDelete)
do {
try NSManagedObjectContext.save()
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic)
} catch let error as NSError {
print("Error \(error.localizedDescription)")
}
}
}
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
switch editingStyle {
case .Delete:
let appDel:AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let context:NSManagedObjectContext = appDel.managedObjectContext
context.deleteObject(items[indexPath.row] as NSManagedObject)
items.removeAtIndex(indexPath.row)
do{
try context.save()
}catch{
print("Error, data not saved!")
}
self.tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
default:
return
}
}