Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Realm results sort on multiple properties ios

I have been trying to sort RLMResults by 2 properties, 1st is sort value and 2nd is name, but no luck. I am getting wrong results when I try to sort with 2 properties.

What I want is I want to sort results using sort value and then alphabetically.

self.allTasks = [[[Task allObjects]
                 sortedResultsUsingProperty:@"priorityLevelSortValue" ascending:YES]
                 sortedResultsUsingProperty:@"taskName" ascending:YES];

Any help would be much appreciable.

Thank you.

like image 875
Paras Gorasiya Avatar asked Apr 02 '16 07:04

Paras Gorasiya


1 Answers

Use -[RLMResults sortedResultsUsingDescriptors:] to sort by multiple properties:

[[Task allObjects] sortedResultsUsingDescriptors:@[
    [RLMSortDescriptor sortDescriptorWithProperty:@"priorityLevelSortValue" ascending:YES],
    [RLMSortDescriptor sortDescriptorWithProperty:@"taskName" ascending:YES]
]];
like image 146
bdash Avatar answered Nov 16 '22 17:11

bdash