0

有没有办法增加一个 NSNumber 实例而不必创建一个新数字?

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

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

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

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

4

1 回答 1

1

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

于 2013-05-26T15:03:20.707 回答