Tuples as the Return Value of Functions
suggest changeFunctions can return tuples:
func tupleReturner() -> (Int, String) {
return (3, "Hello")
}
let myTuple = tupleReturner()
print(myTuple.0) // 3
print(myTuple.1) // "Hello"
If you assign parameter names, they can be used from the return value:
func tupleReturner() -> (anInteger: Int, aString: String) {
return (3, "Hello")
}
let myTuple = tupleReturner()
print(myTuple.anInteger) // 3
print(myTuple.aString) // "Hello"
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents