PDA

View Full Version : Objects That Create Objects




Jordan72
Dec 16, 2005, 01:25 AM
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?


-createNumber:(int)number
{
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.?



robbieduncan
Dec 16, 2005, 02:24 AM
That's all fine. Just remember to release the array in dealloc (this will release all the NSNumbers).