Created
September 25, 2019 19:37
-
-
Save misaki1301/2110875382bf48a978f2edfd26bbb6df to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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