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 2 chalenge

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

    return ("English", "Hello \(person)")
}

var result = greeting("Tom")

whats wrong with this code at the 2 part of tuples?

tuples.swift
func greeting(person: String) -> (language : String, greeting : String){

    return ("English", "Hello \(person)")
}

var result = greeting("Tom")

3 Answers

Chris Shaw
Chris Shaw
26,676 Points

Hi csaba nemeth,

You're very close, you simply have your return type backwards as greeting needs to comes first.

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

var result = greeting("Tom")

What about the 3rd part. It is very confusing, by the way..

Chris Shaw
Chris Shaw
26,676 Points

Task 3 is the simplest part of the challenge and was explained in the previous video, any time you have a named tuple you can access it's value just like you would access a property in a struct.

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

Hi Chris,

Thank you very much! I am appreciated it.

Merry Chrismas!

Chris Shaw
Chris Shaw
26,676 Points

No worries, and Merry Christmas to you too.

Actually the 3rd part is clear, but I don't really understand why confusing the students with this order thing :), everybody knows my code is works perfectly. Add names to return values makes the order pointless, actually thats why it exists.

I very grateful the help tough, cause I sucked about it for 2 hours.