I try to add an swipe to edit option in my TableView. If the User press Edit, then a new View should open.
But I always get an error in the func "editActionsForRowAt" on the line with "if segue.identifier == "ItemDetailsVS {" "": fatal error: unexpectedly found nil while unwrapping an Optional value
The segue have the correct Name in the Storyboard. Any ideas?
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "ItemDetailsVC" {
if let destination = segue.destination as? ItemDetailsViewController {
if let item = sender as? Item2 {
destination.itemToEdit = item
}
}
}
}
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
let edit = UITableViewRowAction(style: .normal, title: "Edit"){ (action, indexPath) in
var segue: UIStoryboardSegue!
if segue.identifier == "ItemDetailsVC" {
if let objects = self.controller.fetchedObjects , objects.count > 0 {
let item = objects[indexPath.row]
self.performSegue(withIdentifier: "ItemDetailsVC", sender: item)
}
}
}
return [edit]
}