Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sorting by expression from NSExpressionDescription

Tags:

ios

core-data

Is it possible to sort data by expression from NSExpressionDescription?

like image 368
Jack Avatar asked Nov 21 '12 15:11

Jack


1 Answers

No, NSSortDescriptor is used to sort results.

Based on the documentation, NSExpressionDescription is used to further narrow your search.

An NSExpressionDescription describes a column to be returned from a fetch that may not appear directly as an attribute or relationship on an entity. Examples might include upper(attribute) or max(attribute). You cannot set an NSExpressionDescription object as a property of an entity.

Fetching Managed Objects provides some code examples of NSExpressionDescription and NSSortDescriptor. Here's a snippet of the NSSortDescriptor example.

// Set example predicate and sort orderings...
NSNumber *minimumSalary = ...;
NSPredicate *predicate = [NSPredicate predicateWithFormat:
    @"(lastName LIKE[c] 'Worsley') AND (salary > %@)", minimumSalary];
[request setPredicate:predicate];

NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc]
    initWithKey:@"firstName" ascending:YES];
[request setSortDescriptors:@[sortDescriptor]];
like image 146
JSuar Avatar answered Nov 13 '22 20:11

JSuar