如何在频率后对数组中的项目进行排序?

How to order items in array after frequency?

我正在编写一个应用程序,您可以在其中对某些球员进行投票,这些球员稍后会存储在云端,然后将他们提取出来进行安排,这样您就可以看到谁获得了最多的选票。

现在我去拿它们

          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);
                    }
                }

还有这个returns

DICTO
1 = "";
2 = 1069451903065548;

这行得通,但稍后我需要过滤这些以查看谁获得了最多的选票。然后我将不得不翻阅字典,似乎我又回到了第 1 个方块。关于如何执行此操作的任何提示,或者是否有从一开始就更简单的方法?

提前致谢, 马丁

这对我有用!

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);