title: What is the most common way to delete cells from a UICollectionView - Swift
body: <p>What is the most common way to delete cells from a <code>UICollectionView</code>? </p>
  
  <p>In a <code>UITableView</code> I use the <code>editActionsForRowAt</code> or <code>editingStyle</code> methods to delete rows, does <code>UIControllerView</code> has something similar or you need to implement your own deleting method?</p>
  
  <p>What I have is a <code>UICollectionView</code> with a lot of photos where each cell/photo is attached to a segue which takes you to a larger version of the photo.</p>
  
  <p>The easiest way I could be to do it in the <code>didSelectItemAt</code> method but in my case that is not an option since as soon as a photo is tapped it segues to the other viewController (larger image).</p>
  
  <p>What would be the best way to add a deleting functionality in a situation like the one I'm describing above?</p>
  
  <p>The following threads show how to delete using the <code>didSelectItemAt</code>.   </p>
  
  <p><a href="https://stackoverflow.com/questions/29610316/how-to-add-a-delete-button-to-collection-view-cell-in-swift">How to add a delete button to Collection View Cell in Swift?</a><br>
  <a href="https://stackoverflow.com/questions/31490358/how-to-delete-item-from-collection-view">How to delete item from collection view?</a>   </p>
  
  <h2>CODE</h2>
  
  <pre><code>func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
      return fruits.count
  }
  public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell{
  
      let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "fruitCustomCell", for: indexPath) as! fruitCollectionViewCell
  
      cell.labelFruitName.text = fruits[indexPath.row].fruitName
      return cell
  }
  </code></pre>
  
  <h2>App Diagram</h2>
  
  <p><a href="https://i.stack.imgur.com/ocdfz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ocdfz.png" alt="enter image description here"></a></p>