views:

332

answers:

1

HI, I have create my iPhone apps but i have a problem. I have a classViewController where i have implemented my program. I must alloc 3 NSMutableArray but i don't want do it in a grapich methods. There isn't a constructor like java for my class? Thanks so much and sorry for my english XP

// I want put it in a method like constructor java

arrayPosizioni = [[NSMutableArray alloc]init];
nomePosizioneCorrente = [NSString stringWithFormat:@"noPosition"];
+3  A: 

Yes, there is an initializer. It's called -init, and it goes a little something like this:

- (id) init {
  self = [super init];
  if (self != nil) {
    // initializations go here.
  }
  return self;
}

Edit: Don't forget -dealloc, tho'.

- (void)dealloc {
  // release owned objects here
  [super dealloc]; // pretty important.
}

As a side note, using native language in code is generally a bad move, you usually want to stick to English, particularly when asking for help online and the like.

Williham Totland
Thanks so much.For the Italian declaration are my mistake. XP
zp26
Another side note, you might want to work on your accept rate. :)
Williham Totland