views:

354

answers:

2

I am new to iphone development.I want a Nsmutable array to hold numbers from 1 to 100.How i can do it.how can i implement in a for loop.Is there any other way to hold numbers in array in iphone.Please help me out.Thanks.

+1  A: 

Use an NSNumber object:

[NSNumber numberWithInt:1];
coneybeare
I am a newbie, can u give more code,of how u save the values in a array.Thanks.
Warrior
+3  A: 

You can only add NSObject subclasses in Cocoa containers. In your case, you will have to wrap your integers in NSNumber objects:

NSMutableArray *array = [NSMutableArray array];
for( int i = 0; i < 100; ++i )
{
   [array addObject:[NSNumber numberWithInt:i]];
}

To extract the values:

int firstValue = [[array objectAtIndex:0] intValue];
Martin Cote
Thanks ,this worked.
Warrior