Let’s Build NSNumber
NSNumber
is a conceptually simple class which mainly exists so that we can stuff numeric values into Cocoa collections, but its flexibility implies a fair amount of underlying complication. By implementing a workalikeMANumber
class, we can see what kinds of thingsNSNumber
has to be doing on the inside. Automatic conversion to different integer types requires a fair amount of boilerplate code, and reliable conversion between number of different types can get pretty complicated.
Python’s implementation of number objects is also interesting.