Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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?

https://www.dropbox.com/s/0kfr4d88e2y5bho/Screenshot%202015-01-05%2021.32.26.png?dl=0

Link above is a screenshot of my error

tuples.swift
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 :)