Skip to content

Instantly share code, notes, and snippets.

@misaki1301
Created September 25, 2019 19:37
Show Gist options
  • Save misaki1301/2110875382bf48a978f2edfd26bbb6df to your computer and use it in GitHub Desktop.
Save misaki1301/2110875382bf48a978f2edfd26bbb6df to your computer and use it in GitHub Desktop.
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
let appDelegate = UIApplication.shared.delegate as! AppDelegate
let context = appDelegate.persistentContainer.viewContext
let code = codes[indexPath.row]
context.delete(code)
codes.remove(at: indexPath.row)
tableView.deleteRows(at: [indexPath], with: .fade)
do {
try context.save()
}catch {
print(error)
}
}
}
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment