Adding an integer onto an array
Posted
by Ohmnastrum
on Stack Overflow
See other posts from Stack Overflow
or by Ohmnastrum
Published on 2010-05-21T20:48:02Z
Indexed on
2010/05/21
20:50 UTC
Read the original article
Hit count: 193
iphone
I'm trying to add random numbers onto the end of this array when ever I call this function. I've narrowed it down to just this so far. when ever I check to see if anything is in the array it says 0. So now i'm quite stumped. I'm thinking that MutableArray releases the contents of it before I ever get to use them. problem is I don't know what to use. A button calls the function and pretty much everything else is taken care of its just this portion inside the function.
NSMutableArray * choices;
-(void) doSomething {
int r = arc4random() % 4;
//The problem...
[choices addObject:[NSNumber numberWithInt:r]];
int anInt = [[choices objectAtIndex:1] integerValue];
NSLog(@"%d", anInt);
//I'm getting nothing no matter what I do.
//some type of loop that goes through the array and displays each element
//after it gets added
}
© Stack Overflow or respective owner