ari
ari

Reputation: 19

How to implement left AND right swipe in SwipeCellKit

I'm following a tutorial to create a simple to-do app where I want the user to be able to swipe left to edit the cell and swipe right to delete the cell by using SwipeCellKit. I have created a swipetableviewcontroller to run the code so that I can call it in other viewcontrollers and have used the code documentation on the github repo SwipeCellKit. This is the code I have added:

func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> [SwipeAction]? {
guard orientation == .right else { return nil }

let deleteAction = SwipeAction(style: .destructive, title: "Delete") { action, indexPath in
    // handle action by updating model with deletion
}

// customize the action appearance
deleteAction.image = UIImage(named: "delete")

return [deleteAction]
}

Where do I implement the LEFT orientation? (Please be kind, i'm just a newbie so I apologise if this is a stupid question)

Upvotes: 0

Views: 681

Answers (1)

Arie Pinto
Arie Pinto

Reputation: 1292

This line is preventing you from implementing the left orientation because the guard statement is only checking for right orientation.

guard orientation == .right else { return nil }

If you want to handle both cases you should change the guard statement to an if statement like this:

if orientation == .right{
   //Do Something with right swipe
}
else{
  //Do Something with left swipe
}

Upvotes: 5

Related Questions