The precise answer depends on what should be displayed as section headers and how the sections should be sorted.
But generally, you have to add a property to the entity, which is then used as sectionNameKeyPath
parameter. In addition, you have to add a first sort descriptor
using the same key (this condition can be relaxed slightly).
For example, if you simply add a string attribute sectionName
to the entity and use
that as sectionNameKeyPath
and as the first sort descriptor key, then all objects
with the same value for sectionName
will be grouped into one section,
and the sections will be sorted by sectionName
.
The remaining
sort descriptors are used to sort the objects within each section.
Another example would be to define a separate entity "Section" with a string attribute
"title" and an integer attribute "index", add a to-one relationship "section" from
"Transaction" to "Section", and use section.index
as sectionNameKeyPath
.
Again, all objects with the same section are grouped together, but the sections are
now sorted by the value of section.index
, and you can modify
tableView:titleForHeaderInSection:
so that the title is displayed in the section
header instead of the index.
This is quite general, but I hope that it gets you started.