Sorting
– sortedArrayHint
– sortedArrayUsingFunction:context:
– sortedArrayUsingFunction:context:hint:
– sortedArrayUsingDescriptors:
– sortedArrayUsingSelector:
– sortedArrayUsingComparator:
– sortedArrayWithOptions:usingComparator:
- - (NSArray *)sortedArrayUsingSelector:(SEL)
comparator
Parameters
- comparator
-
A selector that identifies the method to use to compare two elements at a time. The method should return
NSOrderedAscending
if the receiving array is smaller than the argument,NSOrderedDescending
if the receiving array is larger than the argument, andNSOrderedSame
if they are equal.//selector定义了一个比较两个数组元素的方法,如果此方法返回
NSOrderedAscending说明此元素比参数元素小,如果返回
NSOrderedDescending说明接收的数组元素比参数元素大,NSOrderedSame相等。
Example:一个元素为NSString的数组可以通过调用NSString类中的caseInsensitiveCompare:方法作为Selector。假设anArray已经存在:
NSArray *sortedArray = |
[anArray sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]; |