Order of sections produced by NSFetchedResultsCont

2019-09-10 16:57发布

问题:

Does a NSFetchedResultsController assign values for the attribute identified by sectionNameKeyPath to sections always in ascending order?

For instance if my sectionNameKeyPath were an (optional) boolean attribute with values @(YES), @(NO), @(YES), would the first section receive one row (because NO corresponds to 0) and the second section receive two (because YES corresponds to 1)?

So is that the case and if that is, can one change the order (without introducing another attribute that "inverses" the first)?

回答1:

sortDescriptors is what actually sorts the objects. sectionNameKeyPath simply describes where the section borders should be given that sorting (one section per unique value).