标签:
NSMutableArray *array = [NSMutableArray arrayWithObjects:
[NSDictionary dictionaryWithObjectsAndKeys:@"Obj0", [NSNumber numberWithInt:0], nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Obj5", [NSNumber numberWithInt:5], nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Obj2", [NSNumber numberWithInt:2], nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Obj3", [NSNumber numberWithInt:3], nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Obj1", [NSNumber numberWithInt:1], nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Obj4", [NSNumber numberWithInt:4], nil], nil];
// NSArray *resultArray = [array sortedArrayUsingSelector:@selector(compare:)];
NSArray *resultArray = [array sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
NSNumber *number1 = [[obj1 allKeys] objectAtIndex:0];
NSNumber *number2 = [[obj2 allKeys] objectAtIndex:0];
NSComparisonResult result = [number1 compare:number2];
return result == NSOrderedDescending; // 升序
// return result == NSOrderedAscending; // 降序
}];
标签:
原文地址:http://www.cnblogs.com/paideblogs/p/5148629.html