Reputation: 49
I want to set integer variables that I have put in an NSMutableArray
to zero, here is my code so far but it doesn't work:
[self.pressCountArray addObject:[NSNumber numberWithInt:self.presscount1]];
[self.pressCountArray addObject:[NSNumber numberWithInt:self.presscount2]];
[self.pressCountArray addObject:[NSNumber numberWithInt:self.presscount3]];
[self.pressCountArray addObject:[NSNumber numberWithInt:self.presscount4]];
[self.pressCountArray addObject:[NSNumber numberWithInt:self.presscount5]];
for (NSInteger i = 0; i < [self.pressCountArray count]; i++){
[[self.pressCountArray objectAtIndex:i] integerValue] == 0;
}
Upvotes: 0
Views: 93
Reputation: 30488
You are comparing integer value with 0
and not assigning.
Just this code can accomplish your task
self.pressCountArray[i] = @0;
Upvotes: 1
Reputation: 539705
[self.pressCountArray objectAtIndex:i] integerValue] == 0
compares the current value with zero. To set a new value, use just
self.pressCountArray[i] = @0;
@0
is a "NSNumber literal" and equivalent to [NSNumber numberWithInt:0]
,
see http://clang.llvm.org/docs/ObjectiveCLiterals.html.
You can also simplify your existing code with "boxed expressions":
[self.pressCountArray addObject:@(self.presscount1)];
// ...
Upvotes: 2