Pointer and reference
Essence
In Objective-C (as in C) there are no references as a language construct — only values and pointers. A "reference to an object" in casual speech means a pointer NSString *s: the variable holds the address of a heap object, not the object itself. Assigning a pointer copies the address, so both variables point to the same object; under ARC the assignment also does a retain.
- Scalars and structs (
NSInteger,CGRect) are passed to methods by value — a copy; changes inside are invisible outside. - Objects are passed as pointers: a method can mutate the object (
[array addObject:]) but cannot reassign the caller's variable — it received a copy of the address.
The rest of this answer, with code and interview follow-ups, is in the DevPrep app.
Read the full answer in DevPrep