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

I copy and pasted my code into xcode, and it worked. For some reason, it's not working on treehouse.

It really should work.

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

    return (greeting,language)
}

4 Answers

Andrew Claytor
Andrew Claytor
6,637 Points

You have it really close. Just name the tuples

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

    return (language, greeting)
}

I amended your answers to format the code a little more clearly. If you use the backtick ` rather than the single quote, it will work.

Three backticks before the code, followed immediately by the language name (or filename with extension), then three backticks after the code. If you edit your post you'll see what I mean.

Steve.

That was for Andrew, not Julian! :-)

Andrew Claytor
Andrew Claytor
6,637 Points

Thank you very much! I was trying to figure out how to get the code looking good.

No problem! :-)

Andrew Claytor
Andrew Claytor
6,637 Points
func greeting(person: String) -> (language: String, greeting: String) {
    let language = "English"
    let greeting = "Hello \(person)"

    return (language, greeting)
}

Thanks a lot guys!