Sort by expression from NSExpressionDescription

Is it possible to sort data by expression from NSExpressionDescription ?

+7
source share
1 answer

No, NSSortDescriptor used to sort the results.

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

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

Retrieving managed objects contains some sample code NSExpressionDescription and NSSortDescriptor . Here is an 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]]; 
+1
source

All Articles