1 NSMutableArray *mutArray1 = [[NSMutableArray alloc]init]; 2 NSDictionary *dic = [[NSDictionary alloc]initWithObjectsAndKeys:[NSNumber numberWithInt:98],@"chinese", [NSNumber numberWithInt:68],@"math",[NSNumber numberWithInt:108],@"english",[NSNumber numberWithInt:58],@"politics",nil]; 3 NSArray *array = [dic allValues]; 4 NSLog(@"%@",array); 5 array = [array sortedArrayUsingSelector:@selector(compare:)]; 6 NSLog(@"%@",array); 7 // NSArray *array1 = [dic allKeysForObject:[NSNumber numberWithInt:98]]; 8 // NSString *str2 = [array1 objectAtIndex:0]; 9 // NSLog(@"%@",str2); 10 for (int i = 0; i < array.count; i ++) 11 { 12 NSArray *array2 = [dic allKeysForObject:[array objectAtIndex:i]];//在排好序数组中按照值取键 13 NSString *str2 = [array2 objectAtIndex:0];//在数组中把键取出 14 [mutArray1 addObject:str2];//取出的键加到新的数组中 15 } 16 NSLog(@"mutArray2 = %@",mutArray1); 17 }
时间: 2024-10-26 01:37:14