Editing style for UICollectionView delete

The photo below shows a function to delete a section of a tableview.

 func tableView(_ tableView: UITableView, commit editingStyle:  UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
    if editingStyle == UITableViewCellEditingStyle.delete {
    let appd = UIApplication.shared.delegate as! AppDelegate
    let context = appd.persistentContainer.viewContext

    itemName.remove(at: indexPath.row)

    do {
        try context.save()
    } catch {

I want to know how do do the same thing with a UICollectionView

Hi @timswift, you can try using a pan gesture for deleting a cell within a UICollectionView. I’m not sure if you have already started something on your own or if you have more specific question but here is a tutorial using Swift 3 to do what you are asking. Pan Gesture with UICollectionView Cell .


This topic was automatically closed after 166 days. New replies are no longer allowed.