initialization - How does instantiating an object in the getter work if the setter is used first? -


I am working through the Stanford lecture, calculator tutorial.

  - (NSMutableArray *) operandStack {if ()  

In it to create an example of a model, it suggests a good technique Gives: _operandStack) {_operandStack = [[NSMutableArray alloc] init]; } Return _printerstacks; }

However, for the first time, [operandStack] is used:

  [self.operandStack addObject: operandObject] ;   

Which, I understand, is using setter.

I can see that it clearly works (it moves) - but I understand why no one still tries to get anything from operandStack Has anyone illuminated me, I had no luck with any search.

Your misconception is to suppress the idea that [self OPDSTACK AD Object: Operand Object]; A "setter" operation is to translate that expression into English: "Passing the operation object, send the 'addObject' message to the NSMutableArray received by the method operated stack."

This is a dot notation confusing dot notation only resolves basic function calls, so for example using the familiar class bracket notation, the above mentioned code excerpt can be written. This is the same:

  [[OperntStack itself] addObject: operandObject];   

This form is still completely valid, and is also preferred by some people. In this form, it makes a bit obvious to see that you are actually calling the "Gator" function.

Comments