I have a managed object with a dueDate attribute. Instead of displaying using some ugly date string as the section headers of my UITableView I created a transient attribute
The crash is being caused by the NSFetchedResultsController not knowing about the "done" category before hand and therefore crashing. I have seen this crash a few other times in other questions and with each one I recommend submitting a radar ticket to Apple. This is a bug in the NSFetchedResultsController
.
It looks to me like your problem lies with your "category" transient property that you are using to supply the sectionNameKeyPath
. The sectionNameKeyPath
must order the same as the primary sort descriptor. In your case, this means that all "Overdue" tasks MUST have dates earlier than all "Done" tasks MUST have dates earlier than all "In Progress" tasks. It is possible to construct a scenario where a "Done" task has a dueDate
that comes after an "In Progress" task or comes before an "Overdue" task. This scenario breaks the ordering requirement of the sectionNameKeyPath
and causes the NSFetchedResultsController
to throw an NSInternalConsistencyException
.
I propose a solution to your problem that doesn't involve rolling your own array which then must be split into sections. Create an integer attribute in your model where you map 0 to "Overdue", 1 to "Done", and 2 to "In Progress". Make this the primary sort descriptor in your NSFetchRequest
and sort this property in ascending order. Add a secondary sort descriptor to the NSFetchRequest
that sorts the dueDate
property in ascending order. Modify your category method to derive category names from the integer attribute you created above and use that as your sectionNameKeyPath
. You will need to update the integer attribute to update tasks as they move from in progress to overdue to done, etc.