As the title suggests, I\'m having trouble understanding exactly what a pointer is and why they\'re used. I\'ve searched around a bit but still don\'t really understand. I\'
I have heard the analogy that an object is like a ballon, an the string you're holding it with is the pointer. Typically, code is executed like so:
MyClass *someObj = [[MyClass alloc] init];
The alloc
call will allocate the memory for the object, and the init
will instantiate it with a defined set of default properties depending on the class. You can override init
.
Pointers allow references to be passed to a single object in memory to multiple objects. If we worked with values without pointers, you wouldn't be able to reference the same object in memory in two different places.