With one exception, all objects in Objective-C live exclusively on the heap, which means you will always be dealing with object references.
The one exception is blocks, which can be created on the stack and then subsequently moved to the heap using Block_copy()
. For example:
dispatch_block_t myBlock = ^{
NSLog(@"This is a block that lives on the stack");
};
And due to how they're implemented, blocks can be treated as objects (ie, you can use them anywhere you could use an id
).
Of course, any non-Objective-C objects can be created on the stack. So if you're using Objective-C++, then you can create C++ objects on the stack (like normal), which means you'll be dealing with the object itself and not a reference. Also, any primitive can be created on the stack (int
, char*
, a structure, etc).
So in a nutshell, if you're dealing with objects, then 99.999% of the time you'll be dealing with object references, and never the object itself. Anything else is entirely up to you.