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

Help!

I need help I have no idea what I'm doing wrong!

tuples.swift
func greeting(person: String) ->(greeting: String, language: String) {
    let language = "English"
    let greeting = "Hello \(person)"
 return(greeting: greeting, language: language)
var result = (greeting: "Hello\(Tom)")
}
Josh Schlabach
Josh Schlabach
1,771 Points

Is this the first challenge?

Michael that still doesn't work, it says the same message that I need to assign result to the return greeting.

That is odd. I took your original code and loaded it into Xcode playgrounds. I received two errors. One was the

var result = (greeting: "Hello("Tom")")

which we fixed. The next error was that the code after the return statement wouldn't be executed, which I fixed by making the return statement the last line of code. Compiled and received no errors. I also took out the var result line and the program ran without errors. So I am unsure why you are still receiving that error.

2 Answers

Thomas,

You actually have done everything right. Just make this simple change.

     func greeting(person: String) ->(greeting: String, language: String) {

         let language = "English"
         let greeting = "Hello \(person)"

          var result = (greeting: "Hello\(person)")     // This cannot be "Tom" as it must relate to the greeting constant you created

          return(greeting: greeting, language: language)

    }

     var person = greeting("Tom")
     println(person)                          // This will print out the tuple in the form of ("Hello Tom", "English")

I believe that should solve the issue you are having. "Tom" is the argument you will pass to the tuple outside of the function. Let me know if that helped and made sense

Michael I just posted a new question with what I think is the exact code you told me to use and it still isn't working so if you can see something I'm doing wrong in that let me know

Thomas. In your code you had the result variable after the return which will cause a problem. Looking at all the answers that people provided should produce a result without any errors. If it still causes an error there may be an issue with that challenge.