Is it possible to sort data by expression from NSExpressionDescription
?
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 includeupper(attribute)
ormax(attribute)
. You cannot set anNSExpressionDescription
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]];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With