Language/Objective-C

NSArray Sort

아르비스 2011. 5. 31. 11:14

NSDictionary 로부터 모든 키들을 NSArray  뽑을때 정렬된 상태로 읽는 방법

 

(value값으로 정렬)

NSArray *array = [[dict allKeys] sortedArrayUsingSelector:@selector(compare:)];

 


(대소문자 구분하지않고 정렬)

반환값은 NSComparisonResult

1.

NSArray *sortingArray = [sortedPOI sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];

or

[[self getGlobalName] caseInsensitiveCompare:[aPOI getGlobalName]];

sortedPOI=객체로 만들어진 배열. ([sortedPOI addObject:temp]; 이런식으로)

(특수문자가 맨뒤)

 

2.

NSArray *sortingArray = [sortedPOI sortedArrayUsingSelector:@selector(localizedCompare:)];

or

[[self getGlobalName] localizedCompare:[aPOI getGlobalName]];

(특수문자가 맨앞)


 

(키값으로 정렬.)

(NSArray *)keysSortedByValueUsingSelector:(SEL)selector 메소드를 이용하시면 될듯 싶습니다.

 

가져온 NSDictionary 로부터 1:1 매칭의 자료를 쓰는건 매우 쉽다.

NSString *strKey = [[dict allKeys] objectAtIndex:index];



(NSArray from Sort)
NSArray *sortArray = [inListsortedArrayUsingSelector:@selector(compare:)];