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

Jake N
Jake N
612 Points

Stuck

I got part one but I'm stuck on part 2 an 3, I'm not sure where to start on this one

tuples.swift
func greeting(person: String) -> (language: String, greeting: String) {
    let language = "English"
    let greeting = "Hello \(person)"

    return (greeting,language)
}

3 Answers

Chris Shaw
Chris Shaw
26,676 Points

Hi Jake,

You simply have your return type backwards, greeting should be first then language.

func greeting(person: String) -> (greeting: String, language: String) {
    let language = "English"
    let greeting = "Hello \(person)"

    return (greeting,language)
}

var result = greeting("Tom")
Jake N
Jake N
612 Points

it says i need to define result

Chris Shaw
Chris Shaw
26,676 Points

Sorry Jake, I forgot you said task 2 in your initial post, I've updated my response to include this.

Jake N
Jake N
612 Points

thanks, I'm not able to get the third part either

Chris Shaw
Chris Shaw
26,676 Points

Hi Jake,

The 3rd task is as follows:

Using the println statement, print out the value of the language element from the result tuple.

So what this is asking us to do is print the value for result.language which because we're using named tuples we can access simply via language whereas if we didn't name it we would have to access it via 1 instead.

You can read far more about this in another post I made a while back.

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

println(result.language)

Happy coding!