일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 고양이 산책
- 종이모형
- paper-replika
- CountDiv
- UIAlertView setFrame
- 세팔
- 명랑이
- objective-c
- 블루베리
- 스파르탄
- 태그를 입력해 주세요.
- creative park
- 애완동물
- paper craft
- 식충식물
- PassingCars
- Blueberry
- 실생묘
- 반려동물
- codility
- 세팔로투스
- 아기고양이
- cephalotus
- 끈끈이주걱
- 끄니
- Wall-E
- 산책묘
- ios
- 고양이
- UIAlertView addSubView
Archives
- Today
- Total
꼼시월드
중첩된 딕셔너리의 키를 이용하여 정렬하기 본문
소스코드
NSArray *arr = @[ @{@"name": @"kim", @"profile": @{@"type": @1} }, @{@"name": @"jung", @"profile": @{@"type": @1} }, @{@"name": @"park", @"profile": @{@"type": @2} }, @{@"name": @"hong", @"profile": @{@"type": @2} }, ]; //ascending:YES 오름차순 :NO 내림차순 NSSortDescriptor *typeDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"profile.type" ascending:NO]; NSArray *sortedArray = [arr sortedArrayUsingDescriptors:@[typeDescriptor]]; NSLog(@"sortedArray = %@",sortedArray);
profile 딕셔너리 안에 type 딕셔너리가 중첩된 형태인 경우 중첩된 딕셔너리 키를 이용하여 배열을 정렬하고자 하는 경우 프로퍼티 접근하는것처럼 . 을 이용하여 정렬을 하면 된다. [NSSortDescriptor sortDescriptorWithKey:@"profile.type"];
profile 안의 type으로 내림차순 정렬을 수행하였다.
결과
'iOS' 카테고리의 다른 글
[codility] Task name: PassingCars (0) | 2015.06.10 |
---|---|
UIAlertView addSubView ios7 (0) | 2014.01.29 |
ios 기기의 회전 값 구하기 (0) | 2014.01.21 |
url scheme을 이용하여 카톡,라인,마이피플 앱 설치 확인하기 (0) | 2013.11.26 |
라인 url scheme (0) | 2013.11.26 |
Comments