Note that there are some explanatory texts on larger screens.

plurals
  1. POTransient sectionNameKeyPath & NSSortDescriptor NSFetchedResultsController
    primarykey
    data
    text
    <p>I have a list of tasks within Core Data. I fetch them into a UITableView using an NSFetchedResultsController.</p> <p>I need custom sections in a custom order: </p> <ol> <li>OVERDUE </li> <li>ACTIVE </li> <li>ONGOING </li> <li>POSTPONED </li> <li>COMPLETED</li> </ol> <p>To determine what section a task should go in I use a derived transient attribute calculated on the fly based on other attributes in the relative object. </p> <p>Unfortunately you cannot pass a derived value as a sort descriptor used by a fetch request. This is because a fetch relies on already having data it is being asked to fetch. Chicken &amp; Egg.</p> <p>I understand why I can't do it, that doesn't help me solve the problem!</p> <p>I've tried:</p> <ul> <li><p>Subclassing NSFetchedResultsController to '<a href="http://developer.apple.com/library/ios/DOCUMENTATION/CoreData/Reference/NSFetchedResultsController_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40008227-CH1-DontLinkElementID_2">customise creation of sections and index titles</a>'. Maybe I'm doing this wrong however this just changes the names and orders of sections, not how many things go in those sections (which is critical).</p></li> <li><p>Populating arrays per section and feeding them to the table (clunky, slow yet fully works).</p></li> <li><p>Ripping out ongoing &amp; postponed tasks (which works, but isn't ideal). This way I can sort by dueDate and drive the sectionNameKeyPath via the transient values.</p></li> </ul> <p>Does anyone have any better ideas? There are quite a few questions already just like this one yet none of them come to a neat solution.</p> <p>Thanks in advance!</p> <p>Cheers</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload