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

tuple

i hate treehouse. anyone know how to effing do this?

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

    return (language, greeting)
}

2 Answers

Jack McDowell
Jack McDowell
37,797 Points

Hey there,

It looks like you have 1/3 close, parts 2 & 3 are as follows:

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

    return (greeting, language)
}

var result = greeting("Tom")
println(result.language)

I agree with Jack. That's how I thought println(result.language) should have worked. Treehouse prompts with the Bummer message saying it returns "Hello Tom"

I put the code in a playground and got the same results.

So I used println(result.1) and the playground showed "English"

I entered the same println(result.1) in the Treehouse exercise and received the Well Done message.

Weird. I'll have to keep looking at this.

Okay. I found my error.

I had: return (greeting, language)

It should be: return (language, greeting)

Then you would be able to use:

prinlin(result.language)```