Today, just three quick notes on iPhone development, Objective-C, and Cocoa. Briefly:
- The iPhone has no true fixed-width font
- NSMutableArray isn’t really anything like an array
- NSNumber lets you wrap integers and floats as objects
No Fixed-Width Font
Although the iPhone supports some fonts that are traditionally considered “fixed-width” (e.g. Courier) its implementation of them is a little screwy. In particular, spaces in these fonts don’t take up the same number of pixels as other characters. This means that quick-and-dirty tables and/or ASCII art won’t work consistently on the iPhone. This appears to be a pretty deep problem, as it appears in both Cocoa apps and in web pages viewed with Safari.
NSMutableArray
NSMutableArray is a lot more powerful than its name suggests. In particular, items can be inserted into the middle of an array (e.g. with insertObject:atIndex:) for much less than linear cost. This lets you build a lot of useful data structures with this class. See, for instances, this post.
NSNumber
The Cocoa framework is pretty committed to this object-oriented thing, which can be a bit of a hassle when you’re manipulating non-object primitives (e.g. ints and floats). Fortunately, the NSNumber class is provided to let you (relatively) easily wrap those primitives, s.t. they can be used with, e.g., NSMutableArray.