2D arrays using NSMutableArray

后端 未结 8 844
夕颜
夕颜 2020-11-29 21:41

I need to create a mutable two-dimensional array in Objective-C.

For example I have:

NSMutableArray *sections;
NSMutableArray *rows;
<
8条回答
  •  生来不讨喜
    2020-11-29 22:24

    This is what I did in order to initialize array of arrays.

    NSMutableArray *arrayOfArrays = [[NSMutableArray alloc] initWithCapacity:CONST];
    
    for (int i=0; i<=CONST; i++) {
        [arrayOfArrays addObject:[NSMutableArray array]];
    }
    

    Then later in a code I could simply:

    [[arrayOfArrays objectAtIndex:0] addObject:myObject];
    

提交回复
热议问题