title: Why does my PHFetchResultChangeDetails have changedIndexes, when all I did was insert at the end?
body: <p>I'm writing an iOS8 app using the Photos framework. I'm really loving PHFetchResultChangeDetails.
  But there is something I don't understand: when I save new photos to the camera roll using the following code, then I get back insertions AND changes. I expect only insertions.</p>
  
  <p>To make it concrete:</p>
  
  <pre><code>[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
  
  PHAssetChangeRequest* newPhotoChangeRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:image];
  PHAssetCollectionChangeRequest* albumChangeRequest = [PHAssetCollectionChangeRequest changeRequestForAssetCollection:_album];
  [albumChangeRequest addAssets:[NSArray arrayWithObject:newPhotoChangeRequest.placeholderForCreatedAsset]];
  ...
  </code></pre>
  
  <p>The operation is to insert 3 photos using the above code. Before: 5 photos on ipad. After: 8 photos in ipad.
  Breakpoint on PHFetResultChangeDetails handler shows:</p>
  
  <pre><code>(lldb) po insertionIndexPaths
  &lt;__NSArrayM 0x7913be10&gt;(
  &lt;NSIndexPath: 0x78e39020&gt; {length = 2, path = 0 - 5},
  &lt;NSIndexPath: 0x78e3c910&gt; {length = 2, path = 0 - 6},
  &lt;NSIndexPath: 0x78e39480&gt; {length = 2, path = 0 - 7}
  )
  </code></pre>
  
  <p>--> GOOD: makes sense! these are the photos I just inserted (the last 3 indexpaths).</p>
  
  <pre><code>(lldb) po changeIndexPaths
  &lt;__NSArrayM 0x78e3c420&gt;(
  &lt;NSIndexPath: 0x78e3c7e0&gt; {length = 2, path = 0 - 2},
  &lt;NSIndexPath: 0x78e3c7a0&gt; {length = 2, path = 0 - 3},
  &lt;NSIndexPath: 0x78e3c7b0&gt; {length = 2, path = 0 - 4}
  )
  </code></pre>
  
  <p>--> DON'T UNDERSTAND: why are these considered "changed"? These are the existing photos on the camera roll... I didn't do anything to them.</p>
  
  <p>Thanks for your help.</p>
  
  <p><strong>UPDATE:</strong> it looks like it might have something to do with selection. I neglected to mention, that this happens when there are already some cells selected. What I'm seeing is that when new items are inserted at the end of teh collectionView, then, some selected cells are randomly unselected -- I think the ones that have changeIndexPaths. Wow, that sucks -- I can't see how my code can be doing that! Any hints?</p>
  
  <p><strong>UPDATE2:</strong> so, it appears the spurious changeIndexPaths are always the 3 indexPaths directly before the insertion paths (which are always at the end). Why?!</p>
  
  <p><strong>UPDATE3:</strong> I'm also seeing crashes in UICollectionView's performBatchUpdates, when the datasource is correctly up-to-date beforehand, if there are both inserts and reloads. For example when the change looks like this:</p>
  
  <pre><code>&lt;PHFetchResultChangeDetails: 0x1742b91a0&gt; 
  before=&lt;PHFetchResult: 0x1702b5d20&gt; count=31, 
  after=&lt;PHFetchResult: 0x1702b5ea0&gt; count=33, 
  hasIncremental=1 deleted=(null), 
  inserted=&lt;NSMutableIndexSet: 0x17444aef0&gt;[number of indexes: 2 (in 2 ranges), indexes: (30 32)], 
  changed=&lt;NSMutableIndexSet: 0x17444a9b0&gt;[number of indexes: 4 (in 2 ranges), indexes: (27-29 31)], 
  hasMoves=0
  </code></pre>
  
  <p>... then my app crashes in performBatchUpdates with exception: </p>
  
  <pre><code>*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to delete item 31 from section 0 which only contains 31 items before the update'
  </code></pre>
  
  <p>Here is the code of performBatchUpdates, which I copied straight from Apple documentation (!), so I see no reason why changeIndexPaths contains index 31, given that before the inserts, the count=31:</p>
  
  <pre><code> [self.collectionView performBatchUpdates:^{
  
        if( deletionIndexPaths.count )
                  [self.collectionView deleteItemsAtIndexPaths:deletionIndexPaths];
        if( insertionIndexPaths.count )
                  [self.collectionView insertItemsAtIndexPaths:insertionIndexPaths];
        if( changeIndexPaths.count )
                  [self.collectionView reloadItemsAtIndexPaths:changeIndexPaths];
        if( moveBlock )
                  moveBlock(self.collectionView);
   } ...
  </code></pre>