override func viewDidLoad() {
super.viewDidLoad()
self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "SavedExercise")
let swipeRight = UISwipeGestureRecognizer(target: self, action: #selector(respondToSwipeGesture))
self.view.addGestureRecognizer(swipeRight)
}
@objc func respondToSwipeGesture(gesture: UIGestureRecognizer) {
currentIndex = self.tableView.indexPathForSelectedRow
let ac = UIAlertController(title: "Want to delete from saved exercises?", message: nil, preferredStyle: .actionSheet)
ac.addAction(UIAlertAction(title: "Yes", style: .default, handler: swipedRight))
ac.addAction(UIAlertAction(title: "No", style: .cancel))
}
@objc func swipedRight(action: UIAlertAction) {
if let unwrapped = currentIndex {
savedExercises.remove(at: unwrapped.row)
self.tableView.reloadData()
} else {
print("right swipe messed up somewhere")
}
}
Saw a lot of answers, but they were all in obj-c and not Swift. The current indexPathForSelectedRow variable doesn't seem to do the trick. Thanks!