Does objective-c methods support “pass by value”? Or perhaps to be more specific:
- Is the default behavior for parameters passed into a method pass-by-reference?
- If yes, are there any variations from this in some circumstances – for example if the parameter is just a basic int as opposed to an object? (or is this not relevant in objective-c)
- Is there anyway to have a method support pass-by-value for a basic variable such as int?
- Is there anyway to have a method support pass-by-value for an object? (I’m assuming no here, but for completeness will ask. Of course one could within the message do the copy yourself, however for this approach I’ll consider this not to be something objective-c methods offers you, i.e. rather it was a do-it-yourself)
thanks
No. It’s pass-by-value by default, like in C. Except for the fact that for the Objective C class instance references, the value is a reference. So Objective C class instances are passed effectively by reference.
N/A
See 1.
Not really. You can serialize, pass the string, and recreate inside. Or you can have the object store its ivars as a structure and pass that structure by value. Some objects support cloning.