Prash.......
Prash.......

Reputation: 851

Sorting NSMutableDictionary data

In my application I am having a dictionary which contains Keys A-Z ie 26 characters which are not in sorted ie for eg A,B,C,...... I want to Sort first The dictionary keys alphabetically and also the sort the data related to each key and then again store that in same dictionary.

NSArray *myKeys = [mGlossaryDict allKeys];
NSArray *op = [myKeys sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];

until now here I have an mGlossaryDict which is an Mutabledictionary which is sorted but i need to sort the data from each of the key. Please help me out.

Upvotes: 1

Views: 2965

Answers (1)

ySgPjx
ySgPjx

Reputation: 10265

NSArray *myKeys = [mGlossaryDict allKeys];
NSArray *sortedKeys = [myKeys sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
NSMutableArray *sortedValues = [[[NSMutableArray alloc] init] autorelease];

for(id key in sortedKeys) {
    id object = [myGlossaryDict objectForKey:key];
    [sortedValues addObject:object];
}

Upvotes: 3

Related Questions