Q:

How to order items in array after frequency?

I'm writing an app where you can vote on certain players, these are later stored in the cloud and then they will be fetched for arrangement so you can see who got the most votes.
For now I fetch them
          NSMutableDictionary * dictofvotes = [[NSMutableDictionary alloc] init];
                for (NSString * name in people) {
                    int counts = [self repeatsOf:name people];
                    NSNumber * numero = [NSNumber numberWithInt:counts];
                    if ([dictofvotes objectForKey:name] == nil) {
                        [dictofvotes setObject:name forKey:numero];
                        NSLog(@"DICTO%@", dictofvotes);
                    }
                }

And this returns
DICTO
1 = "";
2 = 1069451903065548;

Which works, but later on I need to filter these to see who got the most votes. Then I would have to swipe through the dictionary and it seems as I am back on square 1 again. Any tips on how to do this or if there is an easier way from the beginning?
Thanks in advance,
Martin

A:

This did the trick for me!
NSMutableDictionary * dictofvotes = [[NSMutableDictionary alloc] init];
                    for (NSString * iden in lobbe) {
                        int counts = [self repeatsOf:iden inArray:lobbe];
                        NSNumber * numero = [NSNumber numberWithInt:counts];
                        if ([dictofvotes objectForKey:iden] == nil) {
                            if (numero > 0) {
                                [dictofvotes setObject:numero forKey:iden];
                            }
                            //[dictofvotes removeObjectForKey:@""];
                            NSLog(@"DICTO%@", dictofvotes);
                            //GO THROUGH VOTES TO SEE WHO HAS MOST STANNAR HÄR
                        }
                    }
                        NSMutableArray * numbers = [[NSMutableArray alloc] initWithObjects:nil];
                        for(id key in dictofvotes) {
                            NSNumber * vote = [dictofvotes objectForKey:key];
                            [numbers addObject:vote];
                        }
                        NSLog(@"NUMBERS:%@", numbers);
                        NSNumber *max=[numbers valueForKeyPath:@"@max.doubleValue"];
                        NSLog(@"MAX%@", max);
                        NSMutableArray * winners = [[NSMutableArray alloc] init];
                        for(id key in dictofvotes) {
                            NSNumber * num = [dictofvotes objectForKey:key];
                            NSLog(@"THENUM:%@", num);
                            if ([num doubleValue] == [max doubleValue]) {
                                NSString * string = key;
                                NSLog(@"THESTRING:%@, THE KEY:%@", string, key);
                                if (![string  isEqual: @""]) {
                                    [winners addObject:string];
                                }

                            }
                        }
                        NSLog(@"WINNERS:%@", winners);

