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

Sara Grim
Sara Grim
5,285 Points

On the tuples Swift Challenge, what does it mean to assign the return value of the "greeting" function to the "result"?

So far I have this in code

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

9 Answers

var result = greeting("Tom")

you're assigning the value of the function "greeting()" to the variable with the name "result"

Richard Nash
Richard Nash
24,862 Points

Thank you David Tonge, totally didn't get that one as well. I think tuples are a little hazy in my mind still.

No worries. I honestly think it's the way the question was worded, because I also had problems with that challenge.

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

return (language, greeting)

}

var result = greeting("Tom") ''' Why do I get an error on this than? "Your result variable has the wrong variable in it. Check instructions..."

Thanks for helping me out. :)

Your syntax is off.

"Hello \(person)"

Missing the forward slash.

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

return (language, greeting)

}

var result = greeting("Tom")

I actually have the fwd slash. It disappeared with the ''' swift formation which went wrong somehow.

I still get the error.

There dissapeared the \ again. I'll see if I can correct this.

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

    return (language, greeting)
}

var result = greeting("Tom")

Could it be that I switched the tuple values and names? I write language, greeting not greeting, language. Also the return value names (language: String, greeting: String)

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

    return (greeting,language)
}

var result = greeting("Tom")

That way around works with the order greeting language.

But why?

I'll give you a clue. Look at the order you declared called the constants then look at the Tuples. I'm very new to the iOS but I'm pretty sure the order has something to do with it