0

I get a variation of the following crash in my project:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (22) must be equal to the number of rows contained in that section before the update (1), plus or minus the number of rows inserted or deleted from that section (8 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'

Soon I will be moving to diffable datasource API, but I'd really want to know what I am doing wrong here, and maybe I can release a bit more stable goodbye version to my iOS 12 users.

I have a Core Data setup with two contexts, a main and a background. The main merges data when the background saves, through notifications. Nothing groundbreaking here. The NSFetchedResultsControllerDelegate updates the tableview with the beingUpdates/endUpdates animation section. I disabled the NSFetchedResultsChangeUpdate updates, so they won't interfere, to isolate the source of the problem.

It seems the app crashes when the updates are in progress and then the fetchedResultsController is loading by calling performFetch. The crash log is not much of a help in this case. Any idea where to look?

There are a couple of good sources e.g. this one, but it does not help in this case.

Thanks for any insights.

Here is the sample project: https://filebin.net/xtordf60rs4pmckk The SampleSOLongerList.zip crashes all the time, but since the list is longer, it might be harder to debug.

Video of the crash: https://youtu.be/D7yoojdpkdQ

The crash happens only at fresh install (not all the time - if more data is preloaded, it happens all the time) To crash the app, you just start it, and then hit Next, and it should crash most of the time.

Zsolt
  • 3,648
  • 3
  • 32
  • 47
  • Does this answer your question? [Why does NSTableView crash when processing deleted rows as NSFetchedResultsControllerDelegate?](https://stackoverflow.com/questions/55976212/why-does-nstableview-crash-when-processing-deleted-rows-as-nsfetchedresultscontr) – Jon Rose Mar 15 '21 at 07:26
  • thanks Jon. I will try to integrate it into the sample project and let you know. – Zsolt Mar 15 '21 at 17:19

0 Answers0