objective-cnsnumber

Why is NSNumber immutable?


Why is NSNumber immutable? Was there a good reason? Because now I am thinking about creating my own class just for the sake of mutability.


Solution

  • A number is a very basic data type. A number is just that - a number. If you mutate it, it just happens to be something else. A number simply cannot change.

    Compare that with more complex data, where the object itself still represents the same thing.