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

Ryan Servais
Ryan Servais
1,350 Points

Issue Running Tuples Function

I ran this function in Xcode and it seemed to work fine, but I can't seem to find why it does not work for the challenge.

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

1 Answer

Greg Kaleka
Greg Kaleka
39,021 Points

Hi Ryan,

Your code worked in Xcode because it's correct code. However, it's not a correct solution to the challenge! The challenge asks for a named tuple as the return type. This code passed the challenge for me:

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

    return (greeting: greeting, language: language)
}

It's a little confusing because the names and the constants are the same, but you could call the constants lang and greet, and your code would look like this:

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

    return(greeting: greet, language: lang)
}

Make sense?

Ryan Servais
Ryan Servais
1,350 Points

Thanks for the clarification! That sheds light on what was going wrong.