Essentially it boils down to this: If you use CGFloat/NSInteger/etc, Apple can make backwards-incompatible changes and you can mostly update your app by just recompiling your code. You really don't want to be going through your app, checking every use of int
and double
.
What backwards-incompatible changes? Plenty!
- M68K to PowerPC
- 64-bit PowerPC
- PowerPC to x86
- x86-64 (I'm not sure if this came before or after iOS.)
- iOS
CGFloat
means "the floating-point type that CoreGraphics" uses: double
on OS X and float
on iOS. If you use CGFloat
, your code will work on both platforms without unnecessarily losing performance (on iOS) or precision (on OS X).
NSInteger
and NSUInteger
are less clear-cut, but they're used approximately where you might use ssize_t
or size_t
in standard C. int
or unsigned int
simply isn't big enough on 64-bit OS X, where you might have a list with more than ~2 billion items. (The unsignedness doesn't increase it to 4 billion due to the way NSNotFound
is defined.)