Is Swift Pass By Value or Pass By Reference

后端 未结 9 749
[愿得一人]
[愿得一人] 2020-11-22 10:04

I\'m really new to Swift and I just read that classes are passed by reference and arrays/strings etc. are copied.

Is the pass by reference the same way as in Objecti

9条回答
  •  清歌不尽
    2020-11-22 10:18

    It is always pass-by-value when the parameter is not inout.

    It is always pass-by-reference if the parameter is inout. However, this is somewhat complicated by the fact you need to explicitly use the & operator on the argument when passing to an inout parameter, so it may not fit the traditional definition of pass-by-reference, where you pass the variable directly.

提交回复
热议问题