Hi, I can't figure out why this code is giving an EXC_BAD_ACCESS. I've tried retaining, casting, and removing the "intValue" on the NSNumbers to no avail. What am I doing wrong?
Code:
-(IBAction)startCalc:(id)sender
{
if (timer == nil)
{
timer = [NSTimer scheduledTimerWithTimeInterval:0.75 target:self selector:@selector(updateProbability) userInfo:nil repeats:YES];
}
if (count == nil)
{
count = [NSMutableArray array];
for (int i = 0; i < range; i++) //Range is non-zero
{
[count addObject:[NSNumber numberWithInt:0]];
}
}
}
-(void)updateProbability
{
NSLog(@"Updating: %i", range);
int i = rand() % range;
NSLog(@"%i", i);
NSLog(@"Should be %@ or %i", [count objectAtIndex:i], [[count objectAtIndex:i] intValue]); //Gives error here or on below line when NSLog is not present
int j = [[count objectAtIndex:i] intValue];
NSLog(@"J: %i", j);
j++;
[count replaceObjectAtIndex:i withObject:[NSNumber numberWithInt:j]];
[self setPercentagesAndUpdate];
}