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

becky hayes
becky hayes
2,226 Points

Trying to assign a tuple to a variable and not sure how to do it!

The Challenge is this: Create a variable named result and assign it the tuple returned from function greeting. (Note: pass the string "Tom" to the greeting function.) and my code is attached. Having trouble knowing what the variable 'result' would look like and how i pass the string to Tom

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



    return (language, greeting, result)
}

1 Answer

Jhoan Arango
Jhoan Arango
14,575 Points

Hello Becky:

What the challenge is asking is for you to create a variable and assign it whatever the function will return to you.

I will modify your code just a bit, and then the rest you can do it. It will make sense once you see it.

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

    return (language, greeting)
}

// Call the function and declare the variable here. 

If you can't solve it or if there is anything that you do not understand, please let me know, and I can go into more details. So far you were doing great.

Good luck