Reputation: 646
In my code I have written this but it fails to compile:
In Class1.h:
@interface Class1 : CCSprite
{
NSMutableArray *leafArr[20][20];
}
@property(readwrite, assign) NSMutableArray *leafArr;
@end
In Class1.m:
@implementation
@synthesize leafArr[20][20];
@end
But this fails to compile, please can you tell me how to make set and set method for a 2D array?
Upvotes: 1
Views: 445
Reputation: 43
int str2Darray[9][9] = {
{-1, -1, -1, 1, 1, 1, -1, -1, -1},
{-1, -1, -1, 1, 1, 1, -1, -1, -1},
{-1, -1, -1, 1, 1, 1, -1, -1, -1},
{1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 0, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1},
{-1, -1, -1, 1, 1, 1, -1, -1, -1},
{-1, -1, -1, 1, 1, 1, -1, -1, -1},
{-1, -1, -1, 1, 1, 1, -1, -1, -1},
};
You can define 5 x 10 matrics as above in .m file. Define flag for leaves in 1 2d array & value into another 2d array. check at the time of display according to your requirement.
Upvotes: 1
Reputation: 20410
There's no way of creating a 2D array in Obj-C, the only thing you can do is create a normal array, and then add arrays to it.
@interface Class1 : CCSprite
{
NSMutableArray *leafArr;
}
@property(readwrite, assign) NSMutableArray *leafArr;
@end
And you add elements with:
[leafArr addObject:mySecondArray];
Upvotes: 2