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

Anyone know what's wrong with this code?

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

    var result = (language"\(greeting) Tom")

    return (greeting, language)
}

What were you hoping to return? "Hello English" or "Hello Tom"?

And what are you expecting the value of the variable 'result' to be? "English Hello Tom"?

Whats the final result you are after?

4 Answers

Here is the prompt: "Create a variable named result and assign it the tuple returned from function greeting. (Note: pass the string "Tom" to the greeting function.)"

I guess I don't really understand what it's asking. I think I want to return "English, Hello Tom"

Disclamer: I have no idea what I'm talking about! making this up as I go along ;) - more working through it than giving you an concise answer I know.

Should the declaration of the var 'result' be outside the function. you have a } at the bottom so it looks like it's all inside. Should it be something like:

var result = greetingLanguage()

what section are you on, I'll see if I can work through it

That section is locked for me. My higher points are from starting Objective-C - I'll just catch up on the Swift ;o)

just found a section on returning tuples that can be named here: http://www.raywenderlich.com/75289/swift-tutorial-part-3-tuples-protocols-delegates-table-views if that helps. let me know if you work it out.

Caught up. This was my answer, hope it helps.

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

    return (greeting, language)
}

var result = greeting("Tom")

println(result.language)