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

Matt Brown
Matt Brown
7,782 Points

Tuples Objective Question - What is wrong with my code?


Link above is a screenshot of my error

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

    return (language, greeting)}

    var result = greeting("Tom")

1 Answer

Stone Preston
Stone Preston
42,016 Points

task 1 states: Make sure to name each item in the tuple: greeting and language

Its not entirely clear but greeting needs to be the first element in the tuple and language second. change your return type and the return tuple around. also be sure that you close the function after the return and the the result constant is created outside of the function scope

// change the return type so that greeting is first, and language second
func greeting(person: String) -> (greeting: String, language: String) {
    let language = "English"
    // make the greeting the first element, and language second
    var greeting = ("Hello \(person)", language )

    return greeting
} //close the function

let result = greeting("Tom")
Matt Brown
Matt Brown
7,782 Points

Wow another speedy response - thanks so much and love the service and help! Would be nice if they specified the order needed. It was working in x-code fine for me so that's why I was pretty confused :)