How to increment a NSNumber

TheLearner picture TheLearner · Jan 25, 2011 · Viewed 74.9k times · Source

How do I increment a NSNumber?

i.e. myNSNumber++

Answer

BoltClock picture BoltClock · Jan 25, 2011

NSNumber objects are immutable; the best you can do is to grab the primitive value, increment it then wrap the result in its own NSNumber object:

NSNumber *bNumber = [NSNumber numberWithInt:[aNumber intValue] + 1];