2

I am getting intermittent and hard to track CoreData exceptions when trying to delete an object from a UITableView.

There's a lot of discussion of this on SO, but they're all specific to a variety of implementations and hard to apply to your own as far as best practice. The tutorials I've seen are helpful for setting up, but not so great at teaching you to problem solve your situation.

What are the best methods to debug/problem solve CoreData errors of this type, and what is the expected flow for correct execution?

Errors like this one:

Serious application error. An exception was caught from the delegate of NSFetchedResultsController during a call to -controllerDidChangeContent:. Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (3) must be equal to the number of rows contained in that section before the update (3), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out). with userInfo (null)

glenstorey
  • 5,134
  • 5
  • 39
  • 71

3 Answers3

0

Did you try using an exception breakpoint? - it should tell you the specific line of code that is causing your exception. To add one go to the breakpoint navigator in xcode, click on the "+" at the bottom left corner of the navigator and hit add exception breakpoint.

kj13ennett
  • 319
  • 1
  • 2
  • 10
  • Thanks, yes I have - all that tells me is that I'm having an error on [self.tablview endupdates] which hasn't been very useful thus far. – glenstorey Mar 17 '12 at 23:29
0

I think all that is happening here, is that you need to adjust whatever NSMutableArray (or whatever) to have the object removed that you are telling the NSFetchedResultsController was just deleted. You had 3 objects before, you indicated one was removed, then it is expecting the rows in section 0 should now contain 2, not the 3 it still detects.

I realize this is not the exact question you're asking, but the "best methods" question might be a bit to general to get a good single answer for.

Scott Corscadden
  • 2,831
  • 1
  • 25
  • 43
  • The problem actually was caused by a superfluous FetchedResultsController with the UITableView set as its delegate (there's a discussion here: http://stackoverflow.com/a/9755379/459116 ) but I still would like some strategies to debug in the future, rather than those specific to this one case. CoreData has always been a bit of a hassle to debug! – glenstorey Mar 18 '12 at 19:23
0

The problem actually was caused by a superfluous FetchedResultsController with the UITableView set as its delegate (there's a discussion here: stackoverflow.com/a/9755379/459116 )

Community
  • 1
  • 1
glenstorey
  • 5,134
  • 5
  • 39
  • 71