views:

68

answers:

2

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 ?

+3  A: 

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];
Dave DeLong
hmm, still getting it using any of those 2 lines, could it be related to my header file ? ( NSArray *atouts; )
Julz
@Julz edited answer
Dave DeLong
@Dave, thanks for looking into it, however it's now erroring like this : "warning: data definition has no type or storage class" - "warning: type defaults to 'int' in declaration of 'atouts'" - " error: conflicting types for 'atouts'"
Julz
A: 

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.

DarkDust
yeah it`s that line :(
Julz