Does objective-c support pass by value methods?

Does objective-c support pass by value methods? Or maybe more specifically:

  • Is the default behavior for parameters passed to the pass-by-reference method?
  • If so, are there any deviations from this in some cases - for example, if the parameter is just a basic int, and not an object? (or this does not apply to objective-c)
  • Is there a way to support the pass-by-value method for a base variable such as int?
  • Is there a way to support the pass-by-value method for an object? (I suppose there isn’t here, but for completeness we’ll ask a question. Of course, you can make a copy in the message yourself, however for this approach I will think that this is not what the objective-c method offers you, i.e. do it yourself)

thank

+5
source share
2 answers
  • No. By default, it is passed by default, as in C. Except for the fact that for references to instances of the Objective-C class, the value is a reference. In this way, instances of the Objective-C class are effectively passed by reference.

  • N / a

  • See 1.

  • Not really. You can serialize, pass a string and recreate inside. Or you can have an object storing it ivars as a structure, and pass that structure by value. Some objects support cloning.

+5
source

Objective-C does not support references, at least not in the sense of the C ++ term.

Objective-C , " " . , , . , ++ ( , ...)

, :

  • , Objective-C pass-by-value. , - .
  • , , , , . , .
  • . . , , , .
  • , , , .
+8

All Articles