简体   繁体   中英

How to create a multidimensional CGPoint array?

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?

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];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM