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 trialSara Grim
5,285 PointsOn 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
David Tonge
Courses Plus Student 45,640 Pointsvar result = greeting("Tom")
you're assigning the value of the function "greeting()" to the variable with the name "result"
Gabriel Kroll
9,823 Points''' 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. :)
David Tonge
Courses Plus Student 45,640 PointsYour syntax is off.
"Hello \(person)"
Missing the forward slash.
Gabriel Kroll
9,823 Pointsfunc 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.
Gabriel Kroll
9,823 PointsThere dissapeared the \ again. I'll see if I can correct this.
Gabriel Kroll
9,823 Pointsfunc greeting(person: String) -> (language:String, greeting:String) {
let language = "English"
let greeting = "Hello \(person)"
return (language, greeting)
}
var result = greeting("Tom")
Gabriel Kroll
9,823 PointsCould 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)
Gabriel Kroll
9,823 Pointsfunc greeting(person: String) -> (greeting:String,language:String) {
let language = "English"
let greeting = "Hello \(person)"
return (greeting,language)
}
var result = greeting("Tom")
Gabriel Kroll
9,823 PointsThat way around works with the order greeting language.
Gabriel Kroll
9,823 PointsBut why?
David Tonge
Courses Plus Student 45,640 PointsI'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
Richard Nash
24,862 PointsRichard Nash
24,862 PointsThank you David Tonge, totally didn't get that one as well. I think tuples are a little hazy in my mind still.
David Tonge
Courses Plus Student 45,640 PointsDavid Tonge
Courses Plus Student 45,640 PointsNo worries. I honestly think it's the way the question was worded, because I also had problems with that challenge.