以相反的顺序对NSArray进行排序 [英] Sorting an NSArray in reverse order

查看:130
本文介绍了以相反的顺序对NSArray进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

NSArray* sortedArray = [myArray sortedArrayUsingSelector:@selector(compare:)];

我想知道如何按降序对这组数字进行排序?

Just wondering how I can sort this array of numbers in descending order?

推荐答案

使用允许您将块作为比较器传递的方法,并实现反转对象的比较器(对NSOrderedDescending返回NSOrderedAscending,反之亦然)。 ...

Either use the method that allows you to pass a block as a comparator and implement a comparator that reverses the objects (returns NSOrderedAscending for NSOrderedDescending and vice versa)....

...或:

NSArray *reversed = [[[myArray sortedArrayUsingSelector:@selector(compare:)] reverseObjectEnumerator] allObjects];

抱歉。得出最重要的部分。

Sorry. Derped the most important part.

这篇关于以相反的顺序对NSArray进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆