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

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!