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 Tuples

Parameters and Tuples Quiz Error

In challenge task 1 of 3 in Stage 2 of Parameters and Tuples (Swift Functions and Optional Course) it states to "Currently our greeting function only returns a single value. Modify it to return both the greeting and the language as a tuple. Make sure to name each item in the tuple: greeting and language. We will print them out in the next task."

I tried this, which seemed to work in playgrounds as I thought, but kept getting the Bummer! error. Any ideas?:

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

let language = "English"

let greeting = "Hello \(person)"



return (greeting, language)

}

3 Answers

Chris Shaw
Chris Shaw
26,650 Points

Hi Jason,

If you remember back to when Amit was explaining about tuples and naming the values he showed a couple of examples of named return values which are tuples, so what the challenge is asking for is what Amit taught in the previous video.

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

    return (greeting, language)
}

One thing Amit doesn't actually teach us it that because these return values are named we can assign them out of order.

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

    return (language: language, greeting: greeting)
}

Not the best names but it's a nice way to see the power of tuples.

Ahh, forgot all about being able to name return values! Thank you sir, you are a genius!

Alejandra González
Alejandra González
947 Points

Hi, Im stuck with the task 3 for this challenge.

"Using the println statement, print out the value of the language element from the result tuple."

what is the result tuple???? I only have the var result in my code :(