How to append values to an array in Objective-C

user440485 picture user440485 · Sep 13, 2010 · Viewed 81.7k times · Source

I'm doing this:

for(int i=0;i>count;i++)
{
    NSArray *temp=[[NSArray alloc]initWIthObjects]i,nil];
    NSLog(@"%i",temp);
}

It returns to me 0,1,2,3....counting one by one, but I want an array with appending these values {0,1,2,3,4,5...}. This is not a big deal, but I'm unable to find it. I am new to iPhone.

Answer

vodkhang picture vodkhang · Sep 13, 2010
NSMutableArray *myArray = [NSMutableArray array];

for(int i = 0; i < 10; i++) {
   [myArray addObject:@(i)];
}

NSLog(@"myArray:\n%@", myArray);