Question

I want to have a 6 by 6 multidimensional array of CGpoints which will hold the vertex locations of 6 horizontal and 6 vertical lines. How would i do this?

Was it helpful?

Solution

If you want to use NSArrays to do this, it would look something like the following:

NSMutableArray* topLevelArray = [NSMutableArray array];
for(int i = 0; i < 6; i++){
    NSMutableArray* innerArray = [NSMutableArray array];
    [topLevelArray addObject:innerArray];
    for(int j = 0; j < 6; j++){
        CGPoint point = CGPointMake(x, y);
        [innerArray addObject:[NSValue valueWithCGPoint:point]];
    }
}

Then, to access a point from your array:

CGPoint point = [topLevelArray[i][j] CGPointValue];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top