-(NSArray *)sortedDevicesByStrength:(NSMutableArray*)devices{ NSArray<HwLanDevice*> *sortedArray = [devices sortedArrayUsingComparator:^(id obj1,id obj2){ long val1 = ((HwLanDevice*)obj1).powerLevel; long val2 = ((HwLanDevice*)obj2).powerLevel; NSLog(@"%lu~%lu",val1,val2); //Ascending order, if you need descending order, you only need to modify the following logic if (val1 < val2) { return NSOrderedAscending; }else{ return NSOrderedDescending; } }]; return sortedArray; }
refer to:
1.https: //www.cnblogs.com/hello-LJ/p/4031471.html
2.http://blog.csdn.net/zfx5130/article/details/42433283