iOS: NSSortDescriptor 集合排序

NSSortDescriptor是专门用来排序的描述符。可以用来排序NSSet,NSDictionary,NSArray.

主要方法:

1. - (instancetype _Nonnull)initWithKey:(NSString * _Nullable)keyPath
                           ascending:(BOOL)ascending

key:按照排序的key。

ascending:升序或降序排列,yes为升序,no为降序。

2. - (instancetype _Nonnull)initWithKey:(NSString * _Nullable)keyPath
                           ascending:(BOOL)ascending
                            selector:(SEL _Nullable)selector

selector:默认情况下,这是一个简单的相等性检查,但它的行为可以通过传递一个选择器(SEL)或者比较器(NSComparator)而发生改变。任何时候当你在为面向用户的字符串排序时,一定要加入localizedStandardCompare:选择器,它将根据当前语言环境的语言规则进行排序(语言环境可能会根据大小写,变音符号等等的顺序而发生改变)。

3.+ (instancetype _Nonnull)sortDescriptorWithKey:(NSString * _Nullable)key
                                     ascending:(BOOL)ascending
                                    comparator:(NSComparator _Nonnull)cmptr

block方法

参考资料:

https://developer.apple.com/library/prerelease/ios/documentation/Cocoa/Reference/Foundation/Classes/NSSortDescriptor_Class/

http://blog.csdn.net/watsy/article/details/17754467

posted @ 2015-08-23 11:38  折半  阅读(824)  评论(0编辑  收藏  举报