Swift in-out variables — passing by reference
1 min readJan 19, 2016
Passing by reference is sometimes convenient depending on your needs. Luckily, if you’re using Swift, it’s pretty simple.
In Swift, you can add the inout keyword in place of var. Here’s an example:
var myInt:Int = 5
func doubleInt(inout myInt:Int) -> Void {
myInt *= 2
}
print(myInt) // 5
doubleInt(&myInt)
print(myInt) // 10
Originally published at Haiku Robot.