这里用到一个自带的方法
as determined by the comparison method specified by a given NSComparator Block.
这个方法是按递增的方式排序的,而怎么定义递增,就看是NSComparator Block怎么设计的了
array = [array sortedArrayUsingComparator:^NSComparisonResult(NSNumber *num1 , NSNumber *num2)
{
// 升序
return [num1 compare:num2];
// 降序
// return [num2 compare:num1];
}];
NSLog(@"%@", array);
sortedArrayUsingComparator
as determined by the comparison method specified by a given NSComparator Block.
这个方法是按递增的方式排序的,而怎么定义递增,就看是NSComparator Block怎么设计的了
array = [array sortedArrayUsingComparator:^NSComparisonResult(NSNumber *num1 , NSNumber *num2)
{
// 升序
return [num1 compare:num2];
// 降序
// return [num2 compare:num1];
}];
NSLog(@"%@", array);