I’m beginning Objective-C and I’m trying to create a multidimensionnal array of integers, here is how I did it :
File Constants.h (added in the Prefix.pch file)
typedef enum {
BOARD_WIDTH=10,
BOARD_HEIGHT=20
} BoardSizeEnum;
File Board.m
@implementation Board
{
NSInteger mBoard[BOARD_WIDTH][BOARD_HEIGHT];
}
I tried many many way of creating constants for my width and height and this way is the only one that seems (quite) correct… I also tried with define but I don’t like this because it’s not typed (am I wrong for thinking that ?)…
Is there a better way of creating this ? I feel it’s not really clean…
Edit :
NSInteger* to NSInteger, I clearly want an array of integers, not pointers.
You shouldn’t declare the sizes like that. Enums are usually used when you have multiple options and you want to give each option a name (instead of just using numbers).
To declare constants for your array, you have a few options.
Use preprocessor macros:
#define BOARD_WIDTH 10Use constants:
static const int boardWidth = 10;And your declaration is wrong. You’re declaring a 2 dimensional array of
NSIntegerpointers. It should be like this instead: