since the editActionsForRowAt is going away I wrote the edit & delete actions using trailingSwipeActionsConfigurationForRowAt, if there's a better way please share. It works but I don't know if (_, _, completionHandler) should be used that way:
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let delete = deleteAction(at: indexPath)
let edit = editAction(at: indexPath)
return UISwipeActionsConfiguration(actions: [delete, edit])
}
//delete
func deleteAction(at indexPath: IndexPath) -> UIContextualAction {
let delete = UIContextualAction(style: .destructive, title: "Delete") { (_, _, completionHandler) in
let company = self.companies[indexPath.row]
self.companies.remove(at: indexPath.row)
self.tableView.deleteRows(at: [indexPath], with: .automatic)
let context = CoreDataManager.shared.persistentContainer.viewContext
context.delete(company)
do {
try context.save()
} catch let deleteErr {
print("Failed to delete company", deleteErr)
}
completionHandler(true)
}
delete.backgroundColor = .mainRed
return delete
}
//edit
func editAction(at indexPath: IndexPath) -> UIContextualAction {
let editAction = UIContextualAction(style: .normal, title: "Edit") { (_, _, completionHandler) in
let editCompanyController = CreateCompanyController()
editCompanyController.company = self.companies[indexPath.row]
let layout = CustomNavigationController(rootViewController: editCompanyController)
editCompanyController.delegate = self
self.present(layout, animated: true, completion: nil)
completionHandler(true)
}
editAction.backgroundColor = .black
return editAction
}