Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone: CoreData, Sorting by 2 columns

I have a table with few columns...And I want to sort it, this is the way how I do that:

NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"column1" 
                                                     ascending:NO];

But if column1 value is 0 everywhere, I want to sort it by another column...@"column2". So how init my sortDescriptor with 2 keys ? thanks

like image 533
Jim Avatar asked Jun 29 '11 10:06

Jim


1 Answers

You don't have to init with two keys. You have to init two sort descriptors. Then add them to an array and then pass that array with sort descriptors to sorting method.

update

NSSortDescriptor *col1SD = [NSSortDescriptor sortDescriptorWithKey:@"column1" ascending:NO];
NSSortDescriptor *col2SD = [NSSortDescriptor sortDescriptorWithKey:@"column2" ascending:NO];

[someMutableArray sortUsingDescriptors:@[col1SD, col2SD]];
like image 62
Eimantas Avatar answered Nov 13 '22 03:11

Eimantas