NSArray Sort

Sorting

      - (NSArray *)sortedArrayUsingSelector:(SEL)

comparator

Parameters
comparator

A selector that identifies the method to use to compare two elements at a time. The method should returnNSOrderedAscending if the receiving array is smaller than the argument, NSOrderedDescending if the receiving array is larger than the argument, and NSOrderedSame if they are equal.

//selector定义了一个比较两个数组元素的方法,如果此方法返回NSOrderedAscending说明此元素比参数元素小,如果返回NSOrderedDescending说明接收的数组元素比参数元素大,NSOrderedSame相等。

Example:一个元素为NSString的数组可以通过调用NSString类中的caseInsensitiveCompare:方法作为Selector。假设anArray已经存在:

 NSArray *sortedArray =
         [anArray sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];



Wangkeke 2012-04-05 17:09 发表评论
原文地址:https://www.cnblogs.com/cokecoffe/p/2537113.html