u Fast Enumeration
n 정의
반복문
Objective-C 2.0에 새로 추가된 기능
NSFastEnumeration 프로토콜을 지원하는 모든 컬렉션(NSArray, NSDictionary, NSSet, NSEnumerator)에서 사용가능.
직접 만든 컬렉션에서 fast enumeration을 지원할려고 하면 NSFastEnumeration 프로토콜을 지원하면 된다.
// one
|
n NSArray 예제
NSArray *array = [NSArray arrayWithObjects:@"One", @"Two", @"Three", @"Four", nil]; |
n NSDictionary 예제
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys: @"quattuor", @"four", @"quinque", @"five", @"sex", @"six", nil]; |
n NSArray ? nextObject 예제
NSArray *array = [NSArray arrayWithObjects:@"One", @"Two", @"Three", @"Four", nil]; |
n index를 이용한 예제
NSArray *array = /* assume this exists */; NSUInteger index = 0; for (id element in array) { NSLog(@"Element at index %u is: %@", index, element); index++; } |
n 아래 두가지 예제는 조건에 따라 일부 처리 요소를 제외할 수 도 있다는 것을 보여줌
NSArray *array = /* assume this exists */; for (id element in array) { if (/* some test for element */) { // statements that apply only to elements passing test } } |
NSArray *array = /* assume this exists */; NSUInteger index = 0; for (id element in array) { if (index != 0) { NSLog(@"Element at index %u is: %@", index, element); } if (++index >= 6) { break; } } |
'아이폰개발' 카테고리의 다른 글
[아이폰개발] 오브젝트별 참고사이트 (0) | 2011.01.21 |
---|---|
[아이폰개발] Objective-C 8.Enabling Static Behavior (0) | 2011.01.13 |
[아이폰개발] Objective-C JSON 통신 모듈 (0) | 2010.12.29 |
[아이폰개발] Objective-C 6.Associative References (0) | 2010.12.20 |
[아이폰개발] Objective-C 5.카테고리와 확장 (0) | 2010.12.20 |