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 trialMartin Mæland
1,713 PointsPlease, I do not understand tuples at all. I am currently working with challenge 1 of 3, any help?
Can somebody help me with this task? Or understanding tuples for that matter. It is so frustrating that I can not figure it out!
func greeting(#person: String) -> String {
let language = "English"
let greeting = "Hello \(person)"
return greeting
}
1 Answer
Chris Stromberg
Courses Plus Student 13,389 PointsA tuple is nothing more than a data type that holds multiple values. In the case below we return a tuple that holds two values.
func greeting(person: String) -> (language: String, greeting: String) {
let language = "English"
let greeting = "Hello \(person)"
return (language,greeting)
}
Martin Mæland
1,713 PointsThank you for helping me out Chris! Now, how do I create a variable "result" and assign it to the tuple that returns from the function "greeting"?
kjvswift93
13,515 Pointskjvswift93
13,515 PointsChris's answer is absolutely right... in addition, Swift 2.0 has removed "#".