iOS可以增加NSNumber,还是需要创建一个新的NSNumber?

时间:2013-05-26 14:53:48

标签: iphone ios objective-c increment nsnumber

有没有办法在不必创建新号码的情况下增加NSNumber实例?

这是我目前正在做的事情:

    int photoIndex = hour + minute/30;
    NSNumber* currentCount =  [self.photosByTime objectAtIndex:photoIndex];

    [self.photosByTime replaceObjectAtIndex:photoIndex withObject:[NSNumber numberWithInt:currentCount.intValue +1]];

有没有办法在不必每次都替换数组内容的情况下进行增量?

1 个答案:

答案 0 :(得分:1)

你做得对,因为NSNUmber不可变,所以每次改变都必须有一个新的。

相关问题