당신이하고있는 방식은 완벽합니다.NSArray
의 기본 배열 (int[][]
, double[][]
등)과 같은 기본 2 차원 구문이 C에 없습니다. 따라서 배열 배열을 사용하여 배열을 중첩해야합니다.
NSString *hello = @"Hello World";
NSMutableArray *insideArray = [[NSMutableArray alloc] initWithObjects:hello,nil];
NSMutableArray *outsideArray = [[NSMutableArray alloc] init];
[outsideArray addObject:insideArray];
// Then access it by:
NSString *retrieveString = [[outsideArray objectAtIndex:0] objectAtIndex:0];
시간에 나중에에서 배열에 액세스하려면, 당신은 같은 것을 할 것 : 여기에 그 작업을 수행하는 방법의 예, 물론
NSArray* innerArray = [mutableArrayPtr objectAtIndex:0];
NSObject* someObject = [innerArray objectAtIndex:0];
을에 0
변경은 어떤 실제로 인덱스를 검색해야합니다.
EDIT :
Q "[있는 NSMutableArray의 arrayWithObjects : imagePtrData, urlInStr, 닐]은 insertObject"2 차원가 "initWithObjects"(또는)인가?
A는 :initWithObjects
및 insertObject
은 모두 두 차원 배열을 만들 수있다. 예를 들어, 당신은 할 수 :
NSMutableArray* arrayOne = [[NSMutableArray alloc] initWithObjects:[NSArray initWithObjects:@"One", @"Two", @"Three", nil], [NSArray initWithObjects:[@"Four", @"Five", @"Six", nil], nil];
// NOTE: You need to release the above array somewhere in your code to prevent a memory leak.
또는 ": [있는 NSMutableArray의 arrayWithObjects : imagePtrData, urlInStr, 전무]은 insertObject"두 차원에는 "initWithObjects"(또는)
NSMutableArray* arrayTwo = [NSMutableArray array];
[arrayTwo insertObject:[NSArray arrayWithObjects:@"One", @"Two", @"Three", nil] atIndex:0];
인가? – Getsy
CFArray에 기본 2D 구문이있을 때? 빌트인 C 배열 타입'T [n]'은 CFArray와 같지 않습니다. – kennytm
@KennyTM : 팁 주셔서 감사합니다. 나는이 맛있는 음식을 반영하기 위해 답을 업데이트했다. 다시 한 번 감사 드리며 매일 새로운 것을 배웁니다. – FreeAsInBeer