The value-key pairs, are in no particular order when stored in an NSDictionary or NSMutableDictionary.
You can just re-write the code by iterating through each key,
and then sort, the values (stored as NSArray/NSMutableArray object, i presume) iteratively.
Assuming, that it is indeed an NSMutableDictionary *dict
for(NSString *key in [dict allKeys])
{
NSArray *arrTimes = [dict objectForKey:key];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"hh:mm a"];
NSArray *arrSortedTimes = [arrTimes sortedArrayUsingComparator:^NSComparisonResult(NSString *obj1, NSString *obj2)
{
NSDate *date1 = [dateFormatter dateFromString:obj1];
NSDate *date2 = [dateFormatter dateFromString:obj2];
return [date1 compare:date2];
}];
[dict setObject:arrSortedTimes forKey:key];
}
You may try this piece of code, and let me know, if you get any problem.