#pragma mark -- 数组排序方法(升序) - (void)arraysortasc{ //数组排序 //定义一个数字数组 nsarray *array = @[@(3),@(4),@(2),@(1)]; //对数组进行排序 nsarray *result = [array sortedarrayusingcomparator:^nscomparisonresult(id _nonnull obj1, id _nonnull obj2) { nslog(@"%@~%@",obj1,obj2); //3~4 2~1 3~1 3~2 return [obj1 compare:obj2]; //升序 }]; nslog(@"result=%@",result); } #pragma mark -- 数组排序方法(降序) - (void)arraysortdesc{ //数组排序 //定义一个数字数组 nsarray *array = @[@(3),@(4),@(2),@(1)]; //对数组进行排序 nsarray *result = [array sortedarrayusingcomparator:^nscomparisonresult(id _nonnull obj1, id _nonnull obj2) { nslog(@"%@~%@",obj1,obj2); //3~4 2~1 3~1 3~2 return [obj2 compare:obj1]; //降序 }]; nslog(@"result=%@",result); } #pragma mark -- 数组排序方法(乱序) - (void)arraysortbreak{ //数组排序 //定义一个数字数组 nsarray *array = @[@(3),@(4),@(2),@(1),@(5),@(6),@(0)]; //对数组进行排序 nsarray *result = [array sortedarrayusingcomparator:^nscomparisonresult(id _nonnull obj1, id _nonnull obj2) { nslog(@"%@~%@",obj1,obj2); //乱序 if (arc4random_uniform(2) == 0) { return [obj2 compare:obj1]; //降序 } else{ return [obj1 compare:obj2]; //升序 } }]; nslog(@"result=%@",result); }
如对本文有疑问, 点击进行留言回复!!
解决Android10读取不到/sdcard/、/storage/emulated/0/文件的问题
Codeforces Round #649 (Div. 2)-B. Most socially-distanced subsequence(思维)
IOS开发教程第一季之UI进阶day2合并IOS学习013--App启动过程、多控制器管理
网友评论