title: insertItemsAtIndexPaths Update Error
body: <p>In UICollectionView, I am trying to use <code>performBatchUpdates:completion</code> to perform updates to my grid view. My data source array is <code>self.results</code>.</p>
  
  <p><strong>Here's my code:</strong></p>
  
  <pre><code>dispatch_sync(dispatch_get_main_queue(), ^{
  
              [self.collectionView performBatchUpdates:^{
  
                  int resultsSize = [self.results count];
                  [self.results addObjectsFromArray:newData];
  
                  NSMutableArray *arrayWithIndexPaths = [NSMutableArray array];
                  if (resultsSize == 0) {
                      [arrayWithIndexPaths addObject:[NSIndexPath indexPathForRow:0 inSection:0]];
                  }
  
                  else {
                      for (int i = 0; i &lt; resultsSize; i++) {
                          [arrayWithIndexPaths addObject:[NSIndexPath indexPathForRow:resultsSize + i inSection:0]];
                      }
                  }
  
                  for (id obj in self.results)
                      [self.collectionView insertItemsAtIndexPaths:arrayWithIndexPaths];
  
              } completion:nil];
  </code></pre>
  
  <p><strong>Explanation of what I have / what I'm doing:</strong></p>
  
  <p>This code runs fine when the initial insertion into the collection view is done. However, when I add/insert more data into my collection view (by updating <code>self.results</code> and calling this), this gives the following error:</p>
  
  <blockquote>
    <p><em>*</em> Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid
    number of items in section 0.  The number of items contained in an
    existing section after the update (8) must be equal to the number of
    items contained in that section before the update (4), plus or minus
    the number of items inserted or deleted from that section (32
    inserted, 0 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 understand this means that the data source wasn't updated properly. However, when querying my <code>self.results</code> array, I see the new count of the data. I am doing that on the first line using <code>addObjectsFromArray</code>. I also stored the old results size in <code>resultsSize</code>. I use that variable to add the newly added index paths into <code>arrayWithIndexPaths</code>.</p>
  
  <p>Now when adding/inserting items, I tried the following for-loops:</p>
  
  <p><code>for (id obj in self.results)</code> which is what I am using now. It works initially but further inserts crashes.</p>
  
  <p><code>for (UIImage *image in newData)</code> works as well initially but further inserts crash.</p>
  
  <p>From the name of the function, I believe that <code>insertItemsAtIndexPaths</code> will insert all items at those index paths without a loop. However, without a loop, the app crashes when it initially tries to populate the data.</p>
  
  <p>I also tried looping from <code>resultsSize + 1</code> until the new <code>self.results</code> count (which contains the new data) and that also crashes at the initial update.</p>
  
  <p>Any suggestions about what I'm doing wrong?</p>
  
  <p>Thank you,</p>