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 trial

iOS Swift Functions and Optionals Parameters and Tuples Tuples

Taylor Smith
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Taylor Smith
iOS Development Techdegree Graduate 14,153 Points

I 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!

Michael Noga
Michael Noga
4,341 Points

We can't see the challenge question you're talking about so you need to show it in your questions.

6 Answers

Chris Shaw
Chris Shaw
26,676 Points

Hi 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.

https://teamtreehouse.com/forum/not-sure-on-the-tuple-question-ios-swift-to-modify-the-greeting-to-return-both-language-and-greeting

Tobi Tron
Tobi Tron
2,737 Points

Hi 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")

Id 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
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Taylor Smith
iOS Development Techdegree Graduate 14,153 Points

oh 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.

I 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
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Taylor Smith
iOS Development Techdegree Graduate 14,153 Points

sorry...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
}

I'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
Chris Shaw
26,676 Points

Hi 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
Brandon Escalante
5,772 Points

Tobias, I've notice random things like this too in other challenges. I hope it's a bug, or I'm learning wrong! haha