title: How to correctly delete a cell from UICollectionView?
body: <p>I am trying to delete a cell form UICollectionView but I am having an error for "Invalid Updates"</p>
  
  <blockquote>
    <p>'Invalid update: invalid number of items in section 0.  The number of items contained in an existing section after the update (9) must be equal to the number of items contained in that section before the update (9), 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>and I tried updating my DataModel before removing the items from the CollectionView, but it didn't work.</p>
  
  <p>here is my Code:</p>
  
  <pre><code>func didChangeQunatityOfCartProductAt(index: IndexPath?, product: ItemsModel?) {
      if let quantity =  product?.quantity{
          if let indexPath = index{
              if quantity == 0{
                  self.products.remove(at: indexPath.row)
                  self.collectionView.deleteItems(at: [indexPath])
              }
          }
      }
  }
  </code></pre>
  
  <p>and here is my numberOfItemsInSection Function:</p>
  
  <pre><code> func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
      return products.count
  }
  </code></pre>
  
  <p>I keep getting the same results even though all I have found on the web is same solution.</p>