Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to establish secondary NSSortDescriptor sort key?

I have successfully sorted the data I have by my sort key lastName, but I want to know how to sort by lastName, and then by firstName. Here is the code I used to sort by lastName

NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"firstName" ascending:YES];
[request setSortDescriptors:[NSArray arrayWithObject:sortDescriptor]];

How do I add the secondary sort key of firstName?

like image 854
tarheel Avatar asked Dec 07 '11 05:12

tarheel


1 Answers

NSSortDescriptor *sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:@"firstName" ascending:YES];
NSSortDescriptor *sortDescriptor2 = [[NSSortDescriptor alloc] initWithKey:@"lastName" ascending:YES];

[request setSortDescriptors:[NSArray arrayWithObjects:sortDescriptor1, sortDescriptor2, nil]];
like image 97
Sergey Kalinichenko Avatar answered Oct 14 '22 03:10

Sergey Kalinichenko