I am storing data in NSMutableDictionary
To store data received by web service.
I want to display data in alpha order but as we know Dictionary store da
NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"Object.Name" ascending:YES];
[items sortUsingDescriptors:[NSArray arrayWithObjects:descriptor,nil]];
Also,
NSArray *ordered = [myDictionary keysSortedByValueUsingComparator:^NSComparisonResult(id obj1, id obj2){
return [obj1.name compare:obj2.name];
}];
Try this,
NSArray *sortedKeys = [dict keysSortedByValueUsingComparator: ^(id obj1, id obj2) {
return (NSComparisonResult)[obj1.name compare:obj2.name];;
}];
You will get all the keys in sortedKeys
array, sorted in the order of object.name
property. You can use these keys to get the values from dictionary as [dict valueForKey:[sortedKeys objectAtIndex:i]]
. For more details please check apple documentation.