I have an NSDictionary that has a key that is a country and object that is an array of cities:
United States
New York
Portland
Austin
San Francisco
India
New Delhi
Belgium
Antwerp
Brussels
I would like to create a dictionary from this dictionary that looks like:
United States
4
Belgium
2
India
1
So sorted from highest number of keys to the lowest number of keys, and the new key is the number of keys in the original dictionary. Is this possible? What would be the most efficient way?
The farthest I've gotten is by using
NSComparator sorter = ^NSComparisonResult(id a, id b)
{
NSArray* a1 = a;
NSArray* a2 = b;
if([a1 count] > [a2 count]) return NSOrderedAscending;
if([a1 count] < [a2 count]) return NSOrderedDescending;
return NSOrderedSame;
}
NSArray* ordered = [dictionary keysSortedByValueUsingComparator:sorter];
But then I only have an ordered array, not that values attached to that array.
Thanks in advance!