记录一种数组排序的方法。
NSArray *unSortedArray = @[@1, @5, @3, @7, @9, @2];
NSLog(@"unSortedArray = %@", unSortedArray);
NSArray *sortedArray = [unSortedArray sortedArrayUsingComparator:^NSComparisonResult(id _Nonnull obj1, id _Nonnull obj2) {
return [obj1 compare:obj2];
}];
NSLog(@"sortedArray = %@", sortedArray);
输出结果为:
2020-04-30 13:40:20.202486+0800 Sorted[3643:1348309] unSortedArray = (
1,
5,
3,
7,
9,
2
)
2020-04-30 13:40:20.202626+0800 Sorted[3643:1348309] sortedArray = (
1,
2,
3,
5,
7,
9
)
网友评论