title: What's the possible cause of this Core Data crash
body: <p>First of all, I'm sorry I can't figure out a better title for this question.</p>
  
  <p>This is a crash that I can not repeat myself but happened to users many times. I'm using HockeyApp(<a href="https://github.com/TheRealKerni/QuincyKit/" rel="nofollow">QuincyKit</a>) to collect crash reports. So I can't debug this problem, I can only read the call stack. But I don't have a clue of what's wrong after reading it. I omitted several irrelevant function calls in the middle.</p>
  
  <p>For the UI part, I'm using <code>NSFetchedResultsController</code> to populate <code>UITableView</code>.</p>
  
  <p>For the Core Data part, I'm using iOS 5's newly introduced parent-child MOCs: parent MOC for the main queue, child MOC for the resource fetching queue. I save child MOC after processing fetched data in it. As soon as I save child MOC, the changes should be pushed into parent MOC automatically by Core Data and FRC should be see the changes and update table view via its delegate. I then call back into the main thread to do extra UI update.</p>
  
  <p>Specifically, I can understand how <code>[UITableView indexPathForRowAtPoint:]</code> called into <code>[NSFetchedResultsController objectAtIndexPath:]</code>, but I can't see why it finally called into my entity's <code>initWithEntity:insertIntoManagedObjectContext:</code> and why <code>initWithEntity:insertIntoManagedObjectContext:</code> would cause unfulfilled fault. I think <code>[NSFetchedResultsController objectAtIndexPath:]</code> should do <code>fetch</code>, but it did <code>insert</code> here.</p>
  
  <pre><code>Exception Type:  SIGABRT
  Exception Codes: #0 at 0x35e7e32c
  Crashed Thread:  0
  
  Application Specific Information:
  *** Terminating app due to uncaught exception 'NSObjectInaccessibleException', reason: 'CoreData could not fulfill a fault for '0xe62bdc0 &lt;x-coredata://327F5799-CAB1-4086-8E75-0E87F0E19BF0/Status/p385&gt;''
  
  Last Exception Backtrace:
  0   CoreFoundation                      0x355c888f __exceptionPreprocess + 162
  1   libobjc.A.dylib                     0x3796f259 objc_exception_throw + 32
  2   CoreData                            0x35f124f3 _PFFaultHandlerLookupRow + 1098
  3   CoreData                            0x35f11d5b _PF_FulfillDeferredFault + 194
  4   CoreData                            0x35f11c0b _sharedIMPL_pvfk_core + 38    
  5   XXX                                0x0008a5c3 -[Tweet initWithEntity:insertIntoManagedObjectContext:] (Tweet.m:125)
  6   XXX                                0x0003fd1b -[Status initWithEntity:insertIntoManagedObjectContext:] (Status.m:333)
  7   CoreData                            0x35f0eded -[NSManagedObject(_NSInternalMethods) _initWithEntity:withID:withHandler:withContext:] + 164
  8   CoreData                            0x35f0de07 -[NSManagedObjectContext(_NSInternalAdditions) _retainedObjectWithID:optionalHandler:withInlineStorage:] + 134
  9   CoreData                            0x35f6b6eb _PFRetainedObjectIDCore + 330
  10  CoreData                            0x35f67065 -[NSManagedObjectContext objectWithID:] + 88
  11  CoreData                            0x35f32c09 _faultBatchAtIndex + 1352
  12  CoreData                            0x35f31e73 -[_PFBatchFaultingArray objectAtIndex:] + 42
  13  CoreData                            0x35f30a87 -[_PFMutableProxyArray objectAtIndex:] + 82
  14  CoreData                            0x35fdd81d -[NSFetchedResultsController objectAtIndexPath:] + 204
  16  XXX                                0x0009ebab -[TweetsViewController tableView:heightForRowAtIndexPath:] (TweetsViewController.m:581)
  17  UIKit                               0x3304dab5 -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 2548
  18  UIKit                               0x33067c3b -[UITableViewRowData rectForSection:] + 302
  19  UIKit                               0x33125981 -[UITableViewRowData indexPathsForRowsInRect:] + 136
  20  UIKit                               0x331258f1 -[UITableView indexPathsForRowsInRect:] + 52
  21  UIKit                               0x33125889 -[UITableView indexPathForRowAtPoint:] + 28
  22  XXX                                0x0009c193 -[TweetsViewController updateUI] (TweetsViewController.m:211)
  25  XXX                                0x00111a6f __block_global_1 (ResourceFetcher.m:68)
  26  libdispatch.dylib                   0x34458b87 _dispatch_barrier_sync_f_slow_invoke + 82
  27  libdispatch.dylib                   0x34457ee7 _dispatch_main_queue_callback_4CF$VARIANT$mp + 194
  28  CoreFoundation                      0x3559b2ad __CFRunLoopRun + 1268
  29  CoreFoundation                      0x3551e4a5 CFRunLoopRunSpecific + 300
  30  CoreFoundation                      0x3551e36d CFRunLoopRunInMode + 104
  31  GraphicsServices                    0x371ba439 GSEventRunModal + 136
  32  UIKit                               0x3302acd5 UIApplicationMain + 1080
  33  XXX                                0x000044ff main (main.m:16)
  34  XXX                                0x00003c50 start + 40
  </code></pre>
  
  <p>Users with this crash problems usually see the table view turns from full-of-cells into empty suddenly immediate before the crash. I think it is am important hint but I can't think of any reasons why all the data is gone suddenly — I don't have code to move or delete the database file.</p>