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

Fahim Karim
Fahim Karim
2,181 Points

Swift Functions Stage 2 Challenge 2

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

    return (language, greeting)
}

let result = greeting("Tom")

I keep getting Your 'result' variable has the wrong value. In the Xcode playground everything seems to be ok.

1 Answer

Hey your return was wrong instead of: return (language, greeting) its:

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

    return (greeting, language)
}

let result = greeting("Tom")
Chris Shaw
Chris Shaw
26,676 Points

I've updated your return types order as it was still the wrong way around.

Fahim Karim
Fahim Karim
2,181 Points

Thanks, that worked. Since it is a named tuple, does the order matter?

Chris Shaw
Chris Shaw
26,676 Points

does the order matter?

No it doesn't, when you're using anything that's named you can specify it out of order such as the below example, all you need to do is simply reference the named value and assign it.

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

    return (greeting: greeting, language: language)
}