Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Swift Functions and Optionals Parameters and Tuples Tuples

Martin Mæland
Martin Mæland
1,713 Points

Please, I do not understand tuples at all. I am currently working with challenge 1 of 3, any help?

Can somebody help me with this task? Or understanding tuples for that matter. It is so frustrating that I can not figure it out!

tuples.swift
func greeting(#person: String) -> String {
    let language = "English"
    let greeting = "Hello \(person)"

    return greeting
}

Chris's answer is absolutely right... in addition, Swift 2.0 has removed "#".

1 Answer

Chris Stromberg
PLUS
Chris Stromberg
Courses Plus Student 13,389 Points

A tuple is nothing more than a data type that holds multiple values. In the case below we return a tuple that holds two values.

func greeting(person: String) -> (language: String, greeting: String) {
    let language = "English"
    let greeting = "Hello \(person)"

    return (language,greeting)
}
Martin Mæland
Martin Mæland
1,713 Points

Thank you for helping me out Chris! Now, how do I create a variable "result" and assign it to the tuple that returns from the function "greeting"?