I'm trying to make a mutableCopy of an NSInteger
?. However, since an NSInteger
is a non-mutable object this doesn't work. If I don't make a mutableCopy of the row variable the UIPickerView
jumps to the next row when selecting one.
Here my code:
- (void)pickerView:(UIPickerView *)pickerView didSelectRow: (NSInteger)row inComponent:(NSInteger)component
{
if (pickerView == _frequencyPicker) {
[_detailTableViewController.currentAlarm.cycles replaceObjectAtIndex:0 withObject:[NSNumber numberWithInteger:row]];
[self.tableView reloadData];
} else {
int rowNumber = (int)row;
// -> mutableCopy
rowNumber++;
NSLog(@"%s:%d",__PRETTY_FUNCTION__,rowNumber);
[_detailTableViewController.currentAlarm.cycles replaceObjectAtIndex: withObject:[NSNumber numberWithInteger:row]];
[self.tableView reloadData];
}
}
Since you are using
NSInteger
, notNSNumber
, you can rewrite your code without declaring and incrementing a primitive variable, like this:Since
NSInteger
is atypedef
for a primitive type, mutability considerations do not apply here.