I want to know a simple thing, which i couldn’t get it is that i want to store 10 values in an integer array dynamically and then i have to check that stored values and compared with the current values whether it is same or not in some other condition. Initially i tried same like C array, int temp[10], but seems to be that is not possible to set and get method, then i tried NSNumber like below,
In AppDelagate file,
NSMutableArray *reqID;
@property (nonatomic,readwrite)
NSMutableArray * reqID;
@synthesize reqID;
........................
........................
........................
In Some other file,
int rd = (1+arc4random() % [arr count]);
[myDelegate.reqID addObject:[NSNumber numberWithUnsignedInteger:rd]];
then i need to check,
for (int i=0; i<10; i++)
{
NSUInteger anInt = [[myDelegate.reqID objectAtIndex:i] unsignedIntegerValue];
if ( anInt==rd )
{
rd = (1+arc4random() % [arr count]);
break;
}
}
But it doesn’ work as expected, i.e array value doesn’t give proper value. i don’t know how to use integer array in Obj-C and handle it to access later etc.
Could someone please explian me?
As well as the stuff Emil has pointed out,
doesn’t give you an array with 10 slots in it, it gives you an empty array with a hint to the runtime that you are eventually going to put 10 things in it. So, if you run youre loop from 0 to 9 before you have added 10 objects, you’ll get an NSRangeException because you’ll run off the end of the array.