In Swift, is there a way to determine through code if a variable passed in is reference type or value type?
For example, is tuple a value type or reference type?
afaik, to pass by reference you need to add the inout
keyword in front of the parameter definition. all other parameters are constants unless prefixed with the var
keyword
“Function parameters are constants by default. Trying to change the value of a function parameter from within the body of that function results in a compile-time error. This means that you can’t change the value of a parameter by mistake.”
and...
“Variable parameters, as described above, can only be changed within the function itself. If you want a function to modify a parameter’s value, and you want those changes to persist after the function call has ended, define that parameter as an in-out parameter instead.”
Excerpt From: Apple Inc. “The Swift Programming Language.” iBooks. https://itun.es/us/jEUH0.l