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

My function returns a tuple that includes both "language and greeting." I have no compiling issues. What am I missing?

?

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

    var tuple = (greeting, language)


    return tuple

}

2 Answers

Thanks, that was it. I had tried just including them in the return result instead of creating the tuple variable, but did not name the return parameters.

Chase Marchione
Chase Marchione
155,055 Points

Hi Cameron,

1) Try naming the return parameters 'greeting' and 'language' in your function header. This will name them in the tuple.

2) Instead of creating a variable named tuple, you can return the values of both of those constants by use of parentheses in your return statement. (Although this isn't necessary, it lessens the number of lines in the code, and eliminates an extra step.)

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

    return (greeting, language)
}

Hope this helps!