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 trialThomas Dikolli
Courses Plus Student 513 PointsHow do I return a tuple with elements named greeting and language
please help
func greeting(#person: String) -> String {
let language = "English"
let greeting = "Hello \(person)"
var tuple = ("greeting", "\(language)")
return tuple
}
1 Answer
Greg Kaleka
39,021 PointsHi Thomas,
We need to change two things here:
- The function "signature", where you show the parameters and return type
- What you're actually returning
There's no need to store the tuple in a variable, though that's certainly one way to do it. Your code is close - you haven't changed the signature, but you are returning a tuple. The tuple isn't quite right though. The challenge is asking for a named tuple.
func greeting(person: String) -> (greeting: String, language: String) { // changed return type
let language = "English"
let greeting = "Hello \(person)"
return (greeting: greeting, language: language) // changed return
}
Note in the tuple I returned, the thing before the colon is the name of that element, which matches the return signature of (greeting: String, language: String)
. This is in the format ([name]: [type], [name]: [type])
.
It's a bit confusing, but hopefully this helps. Let us know if you have more questions!