Saturday, July 7, 2012

Let’s Build NSNumber

Mike Ash:

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 workalike MANumber class, we can see what kinds of things NSNumber 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.

Comments RSS · Twitter

Leave a Comment