3
votes

When i pass a parameter to a swift function does the function copies the parameter or does it uses the reference to that parameter. On value types (struct, enum, tuple) I am sure that the argument is copied to the function. The question is on reference types (objects), what does it happens when they are passed as argument to a swift function?

2

2 Answers

3
votes

When you pass a reference type into a swift function you are passing along a reference to that object, so any changes that you make to the object in that method will effect that object outside the function. You can achieve a similar effect for value types if you label them as inout parameters.

2
votes

Reference types are passed by reference.