Objects That Create Objects

Discussion in 'Mac Programming' started by Jordan72, Dec 15, 2005.

  1. macrumors member

    Nov 23, 2005
    I want to create an instance method that creates several NSNumber instances and then stores their pointers in an NSMutableArray. Is the following implementation an okay way to do this?

    	NSNumber *x = [NSNumber numberWithInt:number];
    	[myArray addObject: x];
    I tried out this method. It has no problem allocating. I have no problem accessing my NSNumbers. I'm just not sure this is the best way to do it.

    Could I get some input on this? Am I facing potential problems I am unaware of, is there a better way to do this, etc.?
  2. Moderator emeritus


    Jul 24, 2002
    That's all fine. Just remember to release the array in dealloc (this will release all the NSNumbers).

Share This Page