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

Mike Rodewald
Mike Rodewald
3,119 Points

Can someone please tell me what I am doing wrong with this checkpoint?

Not sure exactly what I am doing wrong with my code. I defined the two elements in my tuple as 'greeting' and 'language' and proved it out in my Xcode playground, yet this checkpoint keeps saying that it's wrong. Any tips/hints will be greatly appreciated.

Thanks, Mike

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


1 Answer

Matthew Young
Matthew Young
5,133 Points

If you would like to define names for your tuple's values, you need to declare your tuple as such:

var greet = (greetingName: greeting, languageName: language)

However, this would only be named within the scope of your function's closure. If you want to have names for your tuple's values returned outside of your function, you need to define it within your function's return type. Like so:

func greeting(person: String) -> (greetingName: String, languageName: String)

Now when you make your function call and get the tuple returned, you can access the values of your tuple by using their respective names. Like so:

let returnedTuple = greeting("Tom")
print(returnedTuple.greetingName) // prints "Hello Tom"

Check out this link for more details on Tuples: The Swift Programming Language - The Basics - Tuples

Mike Rodewald
Mike Rodewald
3,119 Points

Thank you Matthew for the quick response - I was able to complete the checkpoint from your advice. I was missing assigning the return strings element names (greeting: String, language: String)

I appreciate the help!