title: How to remove elements from collectionview [Swift]
body: <p>In my swift app I have a CollectionView.</p>
  
  <pre><code>extension EditLocalPhotosCollectionCell: UICollectionViewDelegate, UICollectionViewDataSource {
  
  func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
      return imagesPicked.count
  }
  
  func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
  
      photoCell = collectionView.dequeueReusableCell(withReuseIdentifier: "photoCellID", for: indexPath) as! EditLocalPhotoCell
      photoCell.backgroundColor = currentTheme.backgroundColor
      photoCell.photoView.image = imagesPicked[indexPath.row]
  
      photoCell.photoView.layer.masksToBounds = false
      photoCell.photoView.layer.cornerRadius = photoCell.photoView.frame.width / 16
      photoCell.photoView.clipsToBounds = true
  
      let width: CGFloat = 20
  
      deleteButton.setImage(#imageLiteral(resourceName: "close"), for: .normal)
      deleteButton.frame = CGRect(x: photoCell.photoView.frame.width - width / 2, y: 0, width: width, height: width)
      deleteButton.addTarget(self, action: #selector(deletePhoto), for: .touchUpInside)
      photoCell.addSubview(deleteButton)
  
      let longPressure = UILongPressGestureRecognizer(target: self, action: #selector(deletePhoto))
      photoCell.isUserInteractionEnabled = true
      photoCell.addGestureRecognizer(longPressure)
  
      return photoCell
  }
  
  @objc func deletePhoto() {
      isEditingModeActive = true
  }
  
  func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -&gt; CGSize {
      return CGSize(width: 70, height: 70)
  }
  
  func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
  
      if indexPath.row == (CreateLocalTVC.imagesPicked.index(of: #imageLiteral(resourceName: "addPhotos"))) {
          NotificationCenter.default.post(name: NSNotification.Name(rawValue: "ADD_PHOTOS_SELECTED"), object: nil)
      }
  
      if isEditingModeActive &amp;&amp; indexPath.row != (CreateLocalTVC.imagesPicked.index(of: #imageLiteral(resourceName: "addPhotos"))) {
  
          print("REMOVED ITEM AT: \(indexPath)")
  
          collectionView.deleteItems(at: [IndexPath(item: indexPath.row, section: 0)])
          imagesPicked.remove(at: indexPath.row)
          collectionView.reloadData()
      }
  }
  }
  </code></pre>
  
  <p>My idea is to remove a cell when a user tap on it, but, by using this method, occur an error: </p>
  
  <blockquote>
    <p>Invalid update: invalid number of items in section 0.  The number of items contained in an existing section after the update (2) must be equal to the number of items contained in that section before the update (2), plus or minus the number of items inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out).'</p>
  </blockquote>
  
  <p>I deliberately omitted the class in this question because it's not important for my question.
  Thank you.</p>