Hello,
This is how I declare my array :
NSArray *atouts = [[NSArray alloc] arrayWithObjects:@"1",@"2",nil];
but I'm getting :
Initializer element is not constant
What would be the best way to declare a static array then ?
Hello,
This is how I declare my array :
NSArray *atouts = [[NSArray alloc] arrayWithObjects:@"1",@"2",nil];
but I'm getting :
Initializer element is not constant
What would be the best way to declare a static array then ?
You want either:
NSArray * atouts = [[NSArray alloc] initWithObjects:@"1", @"2", nil];
Or:
NSArray * atouts = [NSArray arrayWithObjects:@"1", @"2", nil];
edit however, the real problem is that you can't initialize a static array like this. You have to do something like:
static NSArray * atouts = nil;
//in some method that's invoked early
atouts = [[NSArray alloc] initWithObjects:@"1", @"2", nil];
Are you sure you get that error in that line ? Because the error is about C arrays, AFAIK.
Anyway, instead of [[NSArray alloc] arrayWithObjects:...] you need to use either [[NSArray alloc] initWithObjects:...] or [NSArray arrayWithObjects:...]. Note that the later is autoreleased.