Links

In-Out Parameters | Swift 3

inout keyword is a powerful alternative to tuples for Swift and one thing to make a mistake.

PFB- Some notes worth considering
  1. When the function is called, the value of the argument is copied. (also known as copy-in copy-out or call by value result)
  2. In the body of the function, the copy is modified.
  3. When the function returns, the copy’s value is assigned to the original argument.
  4. In-out parameters cannot have default values.
  5. Variadic parameters cannot be marked as inout.
  6. We must use the ampersand "&" when passing arguments.

Sample:
/// inout

func check ( string: inout String) {
    string = "Innova"
}

var string = "hello"

print(string)
check(string: &string)
print(string)


Post a Comment