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

What should I do in task 2 of 3 Tuples Swift?

It is said here that I have to create a variable named result and assign it the tuple returned from function greeting. (Note: pass the string "Tom" to the greeting function.)

Here is my code:

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

    return (language, greeting)
}

var result = greeting("Tom")

And it doesn't work. I don't know why.

4 Answers

Try this:

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

    return (greeting, language)
}

var result = greeting("Tom")

Notice the first line

"language: String, greeting: String" vs "greeting: String, language: String"

Thank you, Aaron.

just fixed it

Nicolás Carelli
Nicolás Carelli
2,075 Points

Actually, I think there's something wrong there because it said I had an error in:

func greeting(person: String) -> (greeting:String, language:String) { return ("Hello (person)", "language") } var result = greeting("Tom")

BUT NOT IN:

func greeting(person: String) -> (greeting:String, language:String) { return ("Hello (person)", "English") } var result = greeting("Tom")

WHERE "English" and "language" are both strings so...

Nicolás Carelli
Nicolás Carelli
2,075 Points

and in renat and aaron code i think there s not a good re-utilization of parameter names..

Here is the code:

func greeting(person person: String) -> (language: String, greeting: String) {

let language = "English"
let greeting = "Hello \(person)"

return (greeting,language) } var result1 = greeting(person: "Tom")