I’ve the following array containing other arrays.
NSArray *results = [[NSArray alloc] initWithObjects:
[NSArray arrayWithObjects:@"Nickname1", [NSNumber numberWithBool:YES], nil],
[NSArray arrayWithObjects:@"Nickname2", [NSNumber numberWithBool:NO], nil],
[NSArray arrayWithObjects:@"Nickname3", [NSNumber numberWithBool:YES], nil],
[NSArray arrayWithObjects:@"Nickname4", [NSNumber numberWithBool:YES], nil],
nil ];
How do I sort the elements of this array by the second parameter (the boolean one). can I use NSSortDescriptor ? (I want all YES before).
thanks
You can use the
sortedArrayUsingComparatormethod for this. Since you want theYESvalues (a constant of value 1) sorted before theNOvalues (a constant value of 0), just reverse the order of the objects in thecompare:call.