Method Arguments
The names you use to refer to a method’s arguments are also local variables. When the method is executed, whatever arguments are passed to the method are copied into these variables. Because the method is dealing with a copy of the arguments, it cannot change the original values passed to the method. This is an important concept. Suppose you had a method called calculate:, defined as follows:
-(void) calculate: (double) x{ x *= 2; ...}
Also suppose that you used the following message expression to invoke it:
[myData calculate: ptVal];
Whatever value was contained in the variable ptVal would be copied into the local variable x when the calculate method was executed. So changing the value of x inside calculate: would have no ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access