我无法对此进行测试,因为我不在 Mac 上(对不起,如果我拼错了什么),但是:
NSDictionary *dic1 = [NSDictionary dictionaryWithObjectsAndKeys:@"GOD", @"WORD", [NSNumber numberWithInt:8], @"SCORE", nil];
NSDictionary *dic2 = [NSDictionary dictionaryWithObjectsAndKeys:@"DONG", @"WORD", [NSNumber numberWithInt:16], @"SCORE", nil];
NSDictionary *dic3 = [NSDictionary dictionaryWithObjectsAndKeys:@"DOG", @"WORD", [NSNumber numberWithInt:8], @"SCORE", nil];
NSDictionary *dic4 = [NSDictionary dictionaryWithObjectsAndKeys:@"XI", @"WORD", [NSNumber numberWithInt:21], @"SCORE", nil];
NSSortDescriptor *scoreSort = [NSSortDescriptor sortDescriptorWithKey:@"SCORE" ascending:NO];
NSSortDescriptor *wordSort = [NSSortDescriptor sortDescriptorWithKey:@"WORD" ascending:YES];
NSArray *sortedArrayOfDic = [[NSArray arrayWithObjects:dic1, dic2, dic3, dic4, nil] sortedArrayUsingDescriptors:[NSArray arrayWithObjects:scoreSort, wordSort, nil]];
NSLog(@"%@", [sortedArrayOfDict valueForKeyPath:@"WORD"]);
这会做同样的事情,但会有所减少并避免迭代。