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 trialSameer Saxena
3,186 PointsI do not understand what I am doing wrong with Swift tuples. I put (greeting, language) in a var tuple and returned it.
If you see the code, I do not know what I am doing wrong. Should I use string interpolation, is there something I am not using that I should be using? Please tell me. Thank you!
func greeting(person: String) -> (String, String) {
let language = "English"
let greeting = "Hello \(person)"
var tuple = (greeting, language)
return tuple
}
1 Answer
Kenneth Luba
9,781 PointsSameer:
It seems that you are getting a bit confused on what var and return do in the tuple. You are attempting to decompose the tuple so here goes:
func greeting(person: String) -> (language:String, greeting:String) {
let language = "English"
let greeting = "Hello \(person)"
return (greeting, language)
}
var tuple = greeting("Tom")
The first thing that you want to note is that you need to specify which values in your return you are referring to. Set the values for (String, String) as (language, greeting) and add a colon after each. Now, set the return to these values (greeting, language) and, set your tuple variable to call the greeting and pass in the string "Tom". If you put this code in Xcode you'll see the output. Hope this helps.
Kenny