title: correct way of deleting items in collection view
body: <p>I have a collection view of 20 items stored in pictures array. I am deleting selected items with this code:</p>
  
  <pre><code>            self.collectionView.performBatchUpdates({
              let selectedItems = self.collectionView.indexPathsForSelectedItems()!
              self.picturesObject.deleteItemsAtIndexPaths(selectedItems)
              self.collectionView.deleteItemsAtIndexPaths(selectedItems)
  
              }, completion: {_ in})
  </code></pre>
  
  <p>this is the implementation of picturesObject's deleteItemsAtIndexPaths:</p>
  
  <pre><code>func deleteItemsAtIndexPaths(indexPaths:[NSIndexPath]){
          for indexPath in indexPaths{
              pictures.removeAtIndex(indexPath.item)
          }
      }
  </code></pre>
  
  <p>The problem I'm facing is the following. Every time a selected item in collection view is deleted, the pictures array gets smaller. If I delete the first item, than pictures array is only 19 items big. If I than try to delete item number 20 in collection view, the array index gets out of bounds because pictures array is now only 19 object big, but I wanted to delete the 20iest object stored in indexpath.item. </p>
  
  <p><strong>What is the correct way of deleting items in collection view?</strong></p>
  
  <p>EDIT:/// collection view methods</p>
  
  <pre><code>  func numberOfSectionsInCollectionView(collectionView: UICollectionView) -&gt; Int {
          collectionView.allowsMultipleSelection = true
  
          return 1
      }
  
      func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
          return picturesObject.pictures.count
      }
  
      func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -&gt; UICollectionViewCell {
          let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! ShopCell
          cell.imageView.image = picturesObject.pictures[indexPath.item]
  
          return cell
      }
  </code></pre>