You are initializing in viewDidLoad
, However you should do it in init
.
These both are similar, and perfectly valid.
_scores = [[NSMutableArray alloc] initWithObjects:@0,@0,@0,@0,nil];
or,
self.scores=[[NSMutableArray alloc]initWithObjects:@0,@0,@0, nil];
Your last question... Then how do I add (NSNumber *)updateValue to, say, the nth value?
If you addObject:
it will be added at last. You need to insertObject:atIndex:
in your required index, and all following objects will shift to next indices.
NSInteger nthValue=12;
[_scores insertObject:updateValue atIndex:nthValue];
EDIT:
After your edit,
NSInteger previousValue = [[_scores objectAtIndex:baseIndex] integerValue];
NSInteger updatedValue = previousValue + scoreAdjustmentAmount;
[_scores replaceObjectAtIndex:baseIndex withObject:[NSNumber numberWithInt:updatedValue]];