배열(Array)
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
//배열 생성
NSArray *array1 = [[NSArray alloc] initWithObjects:@"A",@"B",@"C", nil];
NSArray *array2 = @[@"1", @"2", @3];
NSLog(@"\narray1 : %@", array1);
NSLog(@"\narray2 : %@", array2);
//배열 요소 접근
NSLog(@"\n2nd item : %@", [array1 objectAtIndex:1]);
NSLog(@"\n1st item : %@", array1[0]);
//for문에서의 배열 접근
for(int i=0; i<[array1 count]; i++)
NSLog(@"\nfor test index:%d, value:%@", i, array1[i]);
for(id element in array2)
NSLog(@"\nfor test2 value %@", element);
}
return 0;
}
==> 결과 :
2019-02-15 11:35:47.514751+0900 Study[1536:287880]
array1 : (
A,
B,
C
)
2019-02-15 11:35:47.514977+0900 Study[1536:287880]
array2 : (
1,
2,
3
)
2019-02-15 11:35:47.515016+0900 Study[1536:287880]
2nd item : B
2019-02-15 11:35:47.515049+0900 Study[1536:287880]
1st item : A
2019-02-15 11:35:47.515064+0900 Study[1536:287880]
for test index:0, value:A
2019-02-15 11:35:47.515078+0900 Study[1536:287880]
for test index:1, value:B
2019-02-15 11:35:47.515092+0900 Study[1536:287880]
for test index:2, value:C
2019-02-15 11:35:47.515117+0900 Study[1536:287880]
for test2 value 1
2019-02-15 11:35:47.515132+0900 Study[1536:287880]
for test2 value 2
2019-02-15 11:35:47.515190+0900 Study[1536:287880]
for test2 value 3
Program ended with exit code: 0
'Objective-C 기초' 카테고리의 다른 글
NSDictionary (0) | 2019.02.15 |
---|---|
가변형 배열(MutableArray) (0) | 2019.02.15 |
가변 문자열 (0) | 2019.02.14 |
파일로 쓰기, 파일 읽기 (0) | 2019.02.14 |
URL Encoding (0) | 2019.02.14 |