IPhone: CoreData, 2 Column Sort

I have a table with several columns ... And I want to sort it, here's how to do it:

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

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

+5
source share
1 answer

You do not need to start with two keys. You must initialize two sort descriptors. Then add them to the array, and then pass that array with sort descriptors to sort.

Update

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

[someMutableArray sortUsingDescriptors:@[col1SD, col2SD]];
+12
source

All Articles