I am new to Objective-C programming, (and C for that matter) and I come from a Java-based programming history. I have some trouble understanding when to use a pointer and when to use a variable instead. My question is this:
Why do I have to type this
NSDate *date = [NSDate date]; Instead of this
NSDate date = [NSDate date]; I feel like I'm not instancing the object, but rather creating its address (or is that the same thing?).
I understand that it makes the program faster to use pass by reference later on, but could someone please clarify the difference as simple as possible for a beginner?
[NSDate date]method is the thing that actually creates a new date object on the heap. The pointer you declare is just used to keep track of the location of the date object. In other words, running alloc init a hundred times would create a hundred objects, you just wouldn't have any way to reference them in the future without keeping a pointer to access them.