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 trialTaylor Smith
iOS Development Techdegree Graduate 14,153 PointsI am stuck on this challenge. I'm not really sure what it's asking me to do. please help!!
I've tried everything and can't seem to move on. please help with specific instructions!
6 Answers
Chris Shaw
26,676 PointsHi Taylor,
Have a read of my answer in the below link and let me know if you have any issues understanding it at all, essentially I've explained in some detail what tuples are and how to implement them as return types.
Tobi Tron
2,737 PointsHi Chris,
I had originally tried the same code you have here but the challenge isn't letting me through! I reversed the order of the items in the tuple and it seems to work. Does that actually matter or are the Treehouse requirements being unnecessarily picky?
Here's the code that lets you through the challenge:
func greeting(person: String) -> (greeting: String, language: String) {
let language = "English"
let greeting = "Hello \(person)"
return (greeting, language)
}
var result = greeting("Tom")
Casey Woelfle
Courses Plus Student 1,861 PointsId like to know if this actually matters too, perhaps we could use the _ like amit said in his videos in some way, to output the info correctly with out reversing the return strings.
Taylor Smith
iOS Development Techdegree Graduate 14,153 Pointsoh my gosh thank you!!! I think it's because Amit never went over naming the tuples in the videos, he simply put (Boolean, String). you are a lifesaver.
Amit Bijlani
Treehouse Guest TeacherNamed tuples are covered in this video: http://teamtreehouse.com/library/functions-and-optionals/parameters-and-tuples/decomposing-a-tuple
Matt Thompson
1,806 PointsI agree Taylor... this stuck me a bit until I read these questions. There is reference in the video Amit linked, but it does not show the tuple values being named in the function declaration... they are merely changed to their proper type and the xcode window is scrolled to content below the declaration for the remainder of the video. I think the video should be updated to show the proper structure. Or, as others have stated on some videos, tips or hints to help when you're stuck would be great.
Taylor Smith
iOS Development Techdegree Graduate 14,153 Pointssorry...I thought it pertained to that section! here is the question:
"Currently our greeting function only returns a single value. Modify it to return both the greeting and the language as a tuple. Make sure to name each item in the tuple: greeting and language. We will print them out in the next task."
and here is the code it starts you with:
func greeting(person: String) -> String {
let language = "English"
let greeting = "Hello \(person)"
return greeting
}
John Fraser
745 PointsI'm having trouble with Tuple challenge question number 2. Here is what I have
Create a variable named result and assign it the tuple returned from function greeting. (Note: pass the string "Tom" to the greeting function.)
func greeting(person: String) -> (language: String, greeting: String) {
let language = "English"
let greeting = "Hello \(person)"
return (language, greeting)
}
var result = greeting(person: "Tom")
result.greeting
Chris Shaw
26,676 PointsHi John,
You're pretty close, all you need is the below, you also don't need to use a named parameter as the function has declared it that way.
func greeting(person: String) -> (language: String, greeting: String) {
let language = "English"
let greeting = "Hello \(person)"
return (language, greeting)
}
var result = greeting("Tom")
Brandon Escalante
5,772 PointsTobias, I've notice random things like this too in other challenges. I hope it's a bug, or I'm learning wrong! haha
Michael Noga
4,341 PointsMichael Noga
4,341 PointsWe can't see the challenge question you're talking about so you need to show it in your questions.