[swift-evolution] Proposal: "out" variables

Amir Michail amichail at gmail.com
Sun Feb 28 12:20:19 CST 2016

Although you could use a tuple of return values to pass data back from a function, doing so when you have many things to pass back is less than ideal.

These “out” variables provide an alternative to multiple return values and must be uninitialized in both the formal and actual parameter contexts.


func f(out x:Int, y:Int) {
	let z = x + 3 // error as x is uninitialized
	x = 2*y // ok

let x1:Int
f(&x1, 2) // ok as x is uninitialized

let x2 = 3
f(&x2, 2) // error as x much be uninitialized

More information about the swift-evolution mailing list