NSArray Sort
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, and?NSOrderedSame
if they are equal.//selector定義了一個比較兩個數組元素的方法,如果此方法返回
NSOrderedAscending說明此元素比參數元素小,如果返回
NSOrderedDescending說明接收的數組元素比參數元素大,NSOrderedSame相等。
-
Example:
-
一個元素為NSString的數組可以通過調用NSString類中的caseInsensitiveCompare:方法作為Selector。
-
假設anArray已經存在:
NSArray *sortedArray = |
[anArray sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]; |
posted on 2012-04-05 17:09 Wangkeke 閱讀(1095) 評論(0) 編輯 收藏 引用 所屬分類: IOS