简体   繁体   中英

iOS can I increment an NSNumber, or do I need to create a new one?

Is there a way to increment a NSNumber instance in place without having to create a new number ?

Here's what I'm doing currently:

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

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

Is there a way to do the increment without having to replace the array contents every time?

您做对了,因为NSNUmber的内容不是可变的,因此每次更改都必须有一个新的内容。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM