please tell me that can we create an array of imteger in objective c i am a new iphone programmer and i am creating an aray which can take an integer from a view (at 0th position)and pass that array to next view and then again put an integer to it (at 1st position) and so on.... please help because it does not accept integer value
+1
A:
You can only store objects in NSArray
s, not primitives (like int
, float
, NSInteger
, etc.), which is probably what you're trying. Use NSNumber
instead.
Shaggy Frog
2010-08-06 05:17:11
but if i useNSNumber *myInt = [NSNumber numberWithInt:sender.tag];[myarray addObject:myInt];it show null on oth position of my array i have already declared my array no compilation problen is there......
Online
2010-08-06 05:22:59
You'll have to rephrase your question. I am having trouble understanding. If you are trying to add objects to an `NSArray` after initialization, that will not work, as it is not a *mutable* class. You will want to use `NSMutableArray` instead.
Shaggy Frog
2010-08-06 05:37:56
A:
What you want to do is add NSNumbers to the array.
[myArray addObject:[NSNumber numberWithInt:myInteger]];
And to access the integer from the array
int myInteger = [[myArray objectAtIndex:myIndex] intValue];
Cappuccino Plus Plus
2010-08-06 06:23:44