Declare a function with inout parameters


I want to declare a function with parameters which it can alter, and call it with a reference.


// Declare a function with 'inout' parameters
func append(inout str:String, withString:String) {
    str += withString
// Declare string variable
var myString = "Hello"

// Call the function with a reference - &
// to our 'myString' variable
append(&myString, withString:" World!")

// The string variable will have now changed


Find answers here

Hi there! Ask Us a Question We are ready to help