Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sort by entity name in NSFetchRequest

I have a fetched results controller that should display all items of a certain entity that has a number of subentities.

The sections in the fetched results controller should be based on the entity name, i.e which subentity an item belongs to. Setting the sectionNameKeyPath to @"entity.name" works.

It seems, however, to be impossible to get the right sort descriptor for the fetch request. Things like [NSSortDescriptor sortDescriptorWithKey:@"entity.name" ascending:YES] result in errors like keypath entity.name not found in entity Something.

like image 226
mrueg Avatar asked Jun 21 '11 19:06

mrueg


1 Answers

Try using [NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES]; You don't need the preceding entitiy, since the entitiy ist already defined by the fetch request. See also the Sort Descriptor Class Reference.

like image 62
Björn Landmesser Avatar answered Sep 28 '22 02:09

Björn Landmesser