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!

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

2 Answers

Can you link to the challenge you are trying to pass and let us know which question - I'm not downloading something to do that when your keyboard is more than capable of doing that. ;-)


Hi Liam, thanks for posting the links.

Let's break the question down. First, it says Currently our greeting function only returns a single value. - OK; we can see that the function only returns one element as the method signature shows this: func greeting(person: String) -> String - the -> String part shows that this function will return a String.

We need to change that, as the question wants, 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

The tuple required should return two variables, and name them appropriately. We need to amend the method signature and what the function returns to do this:

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

    return (greeting, language)

In here, we've modified the returned part of the signature to incorporate the two named strings, as requuested. Also, we've returned them in the bodt of the method too, so the return statement has been amended to correlate with the method signature.

The next part of the challenge incorporates using the method to create a tuple held in a variable and then accessing it using dot notation. Give me a shout if you need a hand with that.