When to and when not to use pointers in Objective-C
You use a pointer always when referring to something on the heap and sometimes, but usually not when referring to something on the stack.
Since Objective-C objects are always allocated on the heap (with the exception of Blocks, but that is orthogonal to this discussion), you always use pointers to Objective-C objects. Both the id
and Class
types are really pointers.
Where you don't use pointers are for certain primitive types and simple structures. NSPoint
, NSRange
, int
, NSUInteger
, etc... are all typically accessed via the stack and typically you do not use pointers.
As for Why the * in Objective-C?
, you might find this question of interest.