0
votes

I'm using the selector for Mac OS X Cocoa App and files of class for Mac OS X Cocoa : Objective C Classes.

I try to initialize an array of 5 integers variables.

The declaration of the array int tipoDeIVA [5] is located in the interface file ..

#import << Foundation/Foundation.h >>

@interface ArticleObj_EX01 : NSObject

{

@public

int tiposDeIVA;

int tipoDeIVA[5];

}

typedef struct article_structure article_a;

...

...

-(void) setInitClass

{

int cont=0;

// the next line give the error called Expected expression, say too "(!) Parse Issue" ..

tipoDeIVA [5]={0,0,0,0,0};

// to get initialize the array I 'need' use a loop for with the next code ..

for (cont=0;cont<5;cont++)

    tipoDeIVA [cont] = 0;

tiposDeIVA = 0;

}

...

I would like get initialize right arrays with multiple values in a single line of code.

Thanks, Sergio Xavier

1
you can't use initialization syntax that way if you've already declared it because it's no longer initialization, it's declaration and then assignment. - Lbatson

1 Answers

0
votes

You cannot initialise the array in a single line of code, you have to use the loop you mention:

for (NSUInteger i = 0; i < 5; i++)
    tipoDeIVA[i] = 0;

Under Objective-C you should probably be using NSArray or NSMutableArray instead.

Also the name of that method looks wrong as a method starting with set is expected to be the setter of a @property, and it should not start with init either, as that is designed for the initializer of the object (that method isn't supposed to be the init method is it?).