I am trying to sort an NSDictionary.
From the Apple Docs, I see that you can use keysSortedByValueUsingSelector :
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:63], @"Mathematics", [NSNumber numberWithInt:72], @"English", [NSNumber numberWithInt:55], @"History", [NSNumber numberWithInt:49], @"Geography", nil]; NSArray *sortedKeysArray = [dict keysSortedByValueUsingSelector:@selector(compare:)];
which gives:
but I want:
I read that you can use compare:options: and NSStringCompareOptions to change the comparison to compare in the other direction.
However, I do not understand how you send compare:options: with an option to the selector.
I want to do something like this:
NSArray *sortedKeysArray = [dict keysSortedByValueUsingSelector:@selector(compare:options:NSOrderDescending)];
How to switch the comparison order?
Related: https://discussions.apple.com/thread/3411089?start=0&tstart=0
cksubs
source share