1
votes

I am using a table view which is being populated by a NSFetchedResultsController. The table show lists. The lists entity has one to many relationship with tasks. Then there is a note entity which has one to one relationship with tasks. After introducing the note entity and relationship with tasks, I am getting this assertion error

error: Serious application error. Exception was caught during Core Data change processing. This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification. Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (1) 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) CoreData: error: Serious application error. Exception was caught during Core Data change processing. This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification. Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (1) 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) 2018-09-02 12:41:37.856931+0500 List24[26505:860491] * 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 (1) 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).' * First throw call stack:

This error never occurred before. However, it is really rarely. Occurred just twice but I have no idea what is causing it.

The notes have one to one relation with tasks. And the deletion is cascading between lists and tasks. So if I delete lists it should delete tasks and that should delete the notes as well.

Any suggestions or tips I can do to try fix it once and for all. Thanks!

1
This error usually occurs when the datasource is not updated correctly just before the deletion. As per the log, it says that your dataSource was reduced by 2 however only 1 row was deleted. Probably just check on your logic where you are modifying your datasource. - Deepika
I am using FRC and just removing the corresponding object from core data. The deletion of row is handled by ‘contentdidchange’ method. One more thing, when i use beginupdates() and endupdates() in controllerwillchange and controllerdidchange methods, the swipe to delete button doesnt appear. Whats wrong here now? - Osama Naeem

1 Answers

0
votes

Invalid update: invalid number of rows in section 0.

The number of rows contained in an existing section after the update (1) 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).

It seems to be a requirement for UITableView(I gues iOS), that if you use .beginUpdates() and .endUpdates(), that you are supposed to call tableView.deletedRows(..) & co the exactly right amount of time to later correspond to what you return from numberOfRows(..).