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

Zachary Goforth
Zachary Goforth
748 Points

How do I pass Challenge Task 2 on tuples?

I recieved this error...

Your function needs to return a tuple with elements named 'greeting' and 'language'

What am I doing wrong?

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

    return (greeting, language) 
}

3 Answers

Just create the variable called result under the function and store the return value of the function in it, like this:

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

    return  (greeting, language)
}

var result = greeting("Tom")

Glad to help

Hi, on that part of the challenge you do not have to worry about print the result, all you have to do is: what are you going to return?, in this case is only the greeting and language, just delete the result part:

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

    return (greeting, language) 
}
Gunnar Magholder
Gunnar Magholder
1,063 Points

Hi Zachary,

you are calling a function inside a function (the call to greeting sits inside the greeting function itself).

Though this is a common concept in functional languages (like LISP, Haskell, etc.) you should only use this type of call in a recursion, that is a function calling itself but at some point in time it is terminating itself instead of calling itself over and over again. By now, I don't know if and why Swift implements recursive functions. So better keep your head out of this, that is don't call a function inside itself (you can call other functions though)