Core Data, NSFetchedResultsController, BAD_ACCESS bug

Hello,


I've been working on this error for a couple of days now and I havn't been able to figure it out. I have a one to many relationship (days have many events) and they're both displayed using two NSFetchedResultsControllers in subsequent tableViewControllers (firstTVC and secondTVC). There is a third view controller that I use to add the events to the days. When I add only the first event on a day (in the thirdVC) the console reads:


*** Assertion failure in -[UITableView _endCellAnimationsWithContext:]


CoreData: error: Serious application error. An exception was caught from the delegate of NSFetchedResultsController during a call to -controllerDidChangeContent:. attempt to delete row 0 from section 0 which only contains 0 rows before the update with userInfo


After logging a bunch I found that the controllerDidChangeContent was called in both the FirstTVC and the SecondTVC and the error logs right after this method is called in the SecondTVC.


  • Then I go back to the secondTVC from the thirdVC and the table does not show the event

    here, the event and day exist in the managed object context (i see it using the MOC registered objects property), yet does not display to the screen

  • so I go back to the firstTVC and then go to the secondTVC and the event is displayed to the screen
    • Then when I delete the event the app crashes with a EXC_BAD_ACCESS error.
    • From the stack I can see the last method to be called prior to the call to save the context that crashes the app is the firstTVC commitEditingStyle method.


If I relaunch the app from this point on it does not crash and operates as expected, until the next day where I have to add the first event.


Can anyone help me figure this bug out?


A lot more random info and screenshots are availible here: https://github.com/iOSDevClass/WeighFit/issues/22


Thank you.

Answered by sprintup in 105687022

I figured it out. The fetchedResultsController delegate had to be set to nil.

Accepted Answer

I figured it out. The fetchedResultsController delegate had to be set to nil.

Core Data, NSFetchedResultsController, BAD_ACCESS bug
 
 
Q