I want to group the results of NSFetchRequest by entity. All entities have one abstract abstract parent. For example:
animal | |-cat | |-dog
NSFetchRequest has includesSubentities set to TRUE and entity to animal . You can set sectionNameKeyPath for NSFetchedResultsController to entity.name , but you cannot do the same with sortDescriptors NSFetchRequest because sortDescriptors are applied to stored attributes (i.e. data in the database, not methods in 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 utility of inheritance. I looked at the SQLite database and the type of the object is stored in the same table as the attributes, so the required data is already in place.
In conclusion: is it possible to sort by subclasses in NSFetchRequest without adding additional attributes?
ios iphone core-data nsfetchrequest
Benedict cohen
source share