You are correct in saying the Objective-C uses pass-by-value; it is not simply the default but the only parameter passing mechanism supported. Objective-C++ supports C++ pass-by-reference as well.
In your expression [self setCount:anNSNumber]
the value in the variable anNSNumber
is passed to setCount
. However that value is a reference of type NSNumber *
, and that reference may be used to modify the object that is referenced.
The value that is passed for a parameter is used to initialise a local variable in the callee, and you can modify the value in that variable without any effect on the caller - this is the definition of call-by-value. So for example you could add to your setCount
:
newCount = [NSNumber numberWithInteger:42];
and that would have no effect on the caller.