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 does my function needs to return a tuple with elements named 'greeting' and 'language'?

I'm on Challenge Task 1 of Tuples and I put in my code below but I got the error...

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

What did I need to change in my code in order to accmpolish this?

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

    return greeting
    return language
}

1 Answer

Chase Marchione
Chase Marchione
155,055 Points

Hi Zachary,

1) In the function header, we'll type a return arrow and then specify the data types of the two return values (that's where the idea of tuples is coming into play... we're dealing with multiple elements)... String, and another String. The challenge asks us to include the names of the elements ('language' and 'greeting') of our tuple, so we'll be sure to do that. 2) We should keep the function's return statement to one line in which both values that we want to return are included. Keeping the return statement to one line is syntactically essential: once a return statement is computed, the role of the function is supposed to be done.

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

    return (greeting, language)
}

Hope this helps!