iOS 数组排序(原创)
NSArray *sortedArray = [userArr sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) { if([VShowUtil isEmptyString:[obj1 objectForKey:@"vlevel"]]) { return NSOrderedDescending; } if([VShowUtil isEmptyString:[obj2 objectForKey:@"vlevel"]]) { return NSOrderedSame; } if ([[obj1 objectForKey:@"vlevel"] intValue] > [[obj2 objectForKey:@"vlevel"] intValue]){ return NSOrderedSame; } if ([[obj1 objectForKey:@"vlevel"] intValue] < [[obj2 objectForKey:@"vlevel"] intValue]){ return NSOrderedDescending; } return NSOrderedSame; }]; [userArr removeAllObjects]; [userArr addObjectsFromArray:sortedArray];
/*! * @Author Yunis_song, 14-12-22 15:12:38 * * @brief 对付费道具进行价格排序 * * @param userArr 付费道具数组 */ - (void)shortArr:(NSMutableArray *)userArr { NSArray *sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"price" ascending:YES]]; [userArr sortUsingDescriptors:sortDescriptors]; }