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

Jacob Pickens
Jacob Pickens
3,435 Points

I can't get the tuples challenge

I did everything I could to try to figure out how to complete it.

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

var tuple = (greeting, language)

return tuple

}

I get the error saying that I need to name the elements 'Greeting' and 'Language'.

So I did this:

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

var (greeting, language) = (greeting, language)

return ///???????

}

But now I don't know how to return it.

Can anyone help?

1 Answer

Stone Preston
Stone Preston
42,016 Points

your first attempt was almost correct. you had

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

    var tuple = (greeting, language)

    return tuple
}

the task states: Make sure to name each item in the tuple: greeting and language. This means the elements in the tuple in the return type need to be named.

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

    var tuple = (greeting, language)

    return tuple
}