Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Swift Functions and Optionals Parameters and Tuples Decomposing a Tuple

Kishan Solomon
Kishan Solomon
1,135 Points

Second objective for Tuples challenge

I don't know what I'm doing wrong here.

The question is:

"Create a variable named result and assign it the tuple returned from function greeting. (Note: pass the string "Tom" to the greeting function.)"

Here's 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 here's my error: "Bummer! Your result variable has the wrong value in it. Check the task instructions again."

I mean, it's a bit weird because greeting is the function and a constant in the function. But the code works fine on my Xcode and it returns the tuple.

I can even return the constant greeting with result.greeting. What am I missing?

I think this might be a bug with the challenge. Maybe you should contact support on this one.

3 Answers

you are on the right track , They ask you to return (greeting and language ) not language then greeting .

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

          return (greeting ,language)
           }

            var result = greeting("Tom")
Kirk Burgess
Kirk Burgess
1,129 Points

I'm not sure how one comes to this conclusion. How is one to know in the 2nd stage of the challenge that greeting & language in the return tuple are listed the wrong way around?

Kishan Solomon
Kishan Solomon
1,135 Points

Oh, you are right. I switched it just so it matched the order they gave it in the function. I forgot they would expect the original order for the Tuple.

Thanks a lot!

I am glad to Help you :)

This is the first time I've been ill with Treehouse. I had the same problem. What gets me ill is task 1 allowed me to use the tuple backwards when I couldn't in task 2. So I assumed I could use the same code as in task 1. I'm also ill that they named the function the same name as one of the constants in the function. Is that common or is there a reason for this? I just spent an hour trying to get it on my own to realize the code from task 1 accepted an incorrect answer. (They wanted greeting then language but it accepted it as language then greeting)

Got it easily after that. Thank you for clarifying the problem, Meek D. I could have been here another 2 hours not realizing I had the tuple backwards.