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

Raymond Eddé
Raymond Eddé
4,092 Points

Please help

I am at the second step of the last tuple exercise and i am asked to: "Create a variable named result and assign it the tuple returned from function greeting. (Note: pass the string "Tom" to the greeting function.)

In Xcode, my "result" value is Hello Tom but in the exercise they give me the “You need assign the return value of the 'greeting' function to 'result’.”

Can someone please help me and tell me what I’m doing wrong?

Jhoan Arango
Jhoan Arango
14,575 Points

Hello..

Try posting your solution here, and we can help you with your problem.

3 Answers

Jhoan Arango
Jhoan Arango
14,575 Points

Raymond:

Looking at your code there are a few things that you have to fix.

First part of the challenge says to return a tuple.

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

    return (greeting, language) // We are returning the tuple
}

Second part, it says to create a variable.

var result = greeting("Tom")

Third part

println(result.language)

Hopefully this helps.

Good luck

Raymond Eddé
Raymond Eddé
4,092 Points

Thanks a Lot! That did the trick.

Raymond Eddé
Raymond Eddé
4,092 Points

So this is the code that works for e in Xcode:

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

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

    var found = (greeting, language)

    return found

}
var (result,_) = greeting("Tom")

result
Eduardo Calvachi
Eduardo Calvachi
6,049 Points

I also got caught by this one, make sure that the order of the returned tuple is the same order as named parameters of the function.