title: NSFetchedResultsController objectAtIndex, objectAtIndexPath, indexPathForObject inconsistencies
body: <p>I have a fetched result with a single section. I am able to access the objects using <code>[[fetchedResultsController fetchedObjects] objectAtIndex:index]</code> for all of the objects. But it is failing when I use objectAtIndexPath like this: <code>[fetchedResultsController objectAtIndexpath:indexPath]</code></p>
  
  <p>An error occurs after I insert an row (for one of the SearchResult objects) into the corresponding table. The object appears to be inserted into the new table correctly. After I have visually confirmed this, I select one of the rows, and then the fun begins.</p>
  
  <p>Here is the code where the error is occurring:</p>
  
  <pre><code>- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  {
      SearchResult *event;
      NSLog(@"Number of sections in fetchedResultsController: %d", [[fetchedResultsController sections] count]);
      for (NSUInteger i=0; i&lt;[[fetchedResultsController fetchedObjects] count]; i++) {
          event = (SearchResult*)[[fetchedResultsController fetchedObjects] objectAtIndex:i];
          NSLog(@"object at index[%d]: %@", i, event.title );
          NSLog(@"indexPath for object at index[%d]:%@", i, [fetchedResultsController indexPathForObject:event]);
      }
  
      NSLog(@"indexPath passed to method: %@", indexPath);
  
      SearchResult *result = [fetchedResultsController objectAtIndexPath:indexPath];  // *** here is where the error occurs ***
  
      [viewDelegate getDetails:result];
  }
  </code></pre>
  
  <p>I am having a failure in the last line. The log looks like this:</p>
  
  <pre><code>Number of sections in fetchedResultsController: 1
  object at index[0]: Cirles
  indexPath for object at index[0]:(null)
  object at index[1]: Begin
  indexPath for object at index[1]:(null)
  object at index[2]: Copy
  indexPath for object at index[2]:(null)
  object at index[3]: Unbound
  indexPath for object at index[3]:(null)
  indexPath passed to method: &lt;NSIndexPath 0x64ddea0&gt; 2 indexes [0, 2]
  </code></pre>
  
  <p>After executing the NSLog statements, I get an exception at the last line using <code>[fetchedResultsController objectAtIndexPath:indexPath]</code>. It happens for other index values too, but they always look valid.</p>
  
  <p><code>*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'no object at index 2 in section at index 0'</code></p>
  
  <p>So, to summarize, there appear to be the right number of fetched objects, there is one section (0), I can access each one by one method, but not by the other. The indexPathForObject: is always returning (null).</p>
  
  <p>Is this a bug or am I misunderstanding something? </p>
  
  <hr>
  
  <p>UPDATE</p>
  
  <p>Here is the code, implementing the NSFetchedResultsControllerDelegate protocol methods.</p>
  
  <pre><code>- (void) controllerWillChangeContent:(NSFetchedResultsController *)controller {
      NSLog(@"Favorites controllerWillChangeContent");
      [self.tableView beginUpdates];
  }
  
  - (void)controllerDidChangeContent:(NSFetchedResultsController *)controller 
  {
      NSLog(@"Favorites Table controllerDidChangeContent");
      [self.tableView endUpdates];
  }
  
  - (void)controller:(NSFetchedResultsController *)controller 
     didChangeObject:(id)anObject 
         atIndexPath:(NSIndexPath *)indexPath 
       forChangeType:(NSFetchedResultsChangeType)type 
        newIndexPath:(NSIndexPath *)newIndexPath {
  
      NSLog(@"Favorites Changed Object");
  
      switch (type) {
          case NSFetchedResultsChangeInsert:
              NSLog(@"--- Favorite was inserted");
              if ([[self.fetchedResultsController fetchedObjects] count] == 1) {
                  // configure first cell to replace the empty list indicator by first deleting the "empty" row
                  [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationNone];
              }
  
              [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationNone];
  
              break;
  
          case NSFetchedResultsChangeDelete:
              NSLog(@"--- Favorite was deleted");
  
              [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
              if ([[self.fetchedResultsController fetchedObjects] count] == 0) {
                  // configure first cell to show that we have an empty list
                  [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
              }
  
              break;
  
          case NSFetchedResultsChangeMove:
              NSLog(@"--- Favorite was moved");
  
              break;
  
          case NSFetchedResultsChangeUpdate:
              NSLog(@"--- Favorite was updated");
              [self configureCell:(ResultCell*)[tableView cellForRowAtIndexPath:indexPath] atIndexPath:indexPath];
  
              break;
  
          default:
              break;
      }
  
  }
  
  - (void)controller:(NSFetchedResultsController *)controller
    didChangeSection:(id &lt;NSFetchedResultsSectionInfo&gt;)sectionInfo 
             atIndex:(NSUInteger)sectionIndex 
       forChangeType:(NSFetchedResultsChangeType)type {
  
      switch (type) {
          case NSFetchedResultsChangeInsert:
              NSLog(@"Favorites Section Added");
  
              break;
  
          case NSFetchedResultsChangeDelete:
              NSLog(@"Favorites Section Deleted");
  
              break;
  
          default:
              break;
      }
  
  }
  </code></pre>
  
  <hr>
  
  <p>UPDATE 2</p>
  
  <p>I don't know if it matters, but the tableView is initialized with this line:</p>
  
  <pre><code>    tableView = [[UITableView alloc] initWithFrame:CGRectMake(...) style:UITableViewStyleGrouped];
  </code></pre>
  
  <hr>
  
  <p>UPDATE 3</p>
  
  <p>When I change the offending line as follows, it works fine. But I would rather keep the indexing the same as it is with the table.</p>
  
  <pre><code>//SearchResult *result = [self.fetchedResultsController objectAtIndexPath:indexPath];
  SearchResult *result = [[self.fetchedResultsController fetchedObjects] objectAtIndex:[indexPath indexAtPosition:1]]
  </code></pre>