I want to group the results of a NSFetchRequest
by entity. The entities all share the same abstract parent. For example:
animal
|
|-cat
|
|-dog
The NSFetchRequest
has includesSubentities
set TRUE
and entity
set to animal
. It is possible to set sectionNameKeyPath
of NSFetchedResultsController to entity.name
but it is not possible to do the same with the sortDescriptors
of the NSFetchRequest
due to the fact that the sortDescriptors
are applied to the stored attributes (i.e. data in the database, not methods on the classes). Therefore the only way to group by entity type is to add an attribute to the superclass that subclasses can use to identify themselves.
This seems crazy as it undermines the usefulness of inheritance. I had a look in the SQLite database and the entity type is stored in the same table as the attributes so the required data is already in place.
In summary: Is it possible to sort by subclasses in an NSFetchRequest
without adding additional attributes?