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

Sain-R Edwards Jr.
Sain-R Edwards Jr.
1,853 Points

Tuples

Tuples, tuples, tuples...Can someone lead me in the right direction on how to, "Create a variable named result and assign it the tuple returned from function greeting. (Note: Pass the string "Tom" to the greeting function.)? More specifically, I keep receiving a "Bummer" with assigning the return value of the greeting function to result.

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

    return (greeting, language)
    var result(greeting: "Tom")
}

3 Answers

Vittorio Somaschini
Vittorio Somaschini
33,371 Points

Hello Sain-R.

Please note that in general when you write return ..... the function is basically done: if you write code (inside the function, but after the return statement, it won't be executed).

In your case, you want to declare a variable outside, the function, so code needs to go beneath it.

Your piece of code "var result" looks correct, but then we need to assign it (using the "=" sign) to the function call, passing the "Tom" string as the parameter inside the parenthesis.

Let me know if this makes it clear.

Vittorio

Sain-R Edwards Jr.
Sain-R Edwards Jr.
1,853 Points

Thanks for your quick response and great explanation Vittorio Somaschini ! I really appreciate you reaching out trying to help me on such a short notice. I'm still missing something but will have to figure it out tomorrow. I'm not a programmer by nature and this one thing seems to be very challenging.

you are on the right track.. you just need to call that result variable outside of the function

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

     var result(greeting: "Tom")

hope that helps

Sain-R Edwards Jr.
Sain-R Edwards Jr.
1,853 Points

Thanks Meek D ! I may need some rest. I've been at this a little too long today. I will give it another whirl tomorrow. My brain is fried.

No problem man !!!

did the code work ? Sain-R Edwards Jr.

Sain-R Edwards Jr.
Sain-R Edwards Jr.
1,853 Points

Thanks again Meek D and Vittorio Somaschini. I was missing the # symbol before "person" in the function parameter. I also found out that I needed to write my answer as " var result = greeting(person: "Tom") "

we are glad that we help you :)