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

Still need help

This question is specifically for Michael Lazarz but if anyone could help that would be great, Michael this is the exact code you gave me and it is still coming up with an error, Am I doing something 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)")
}
func greeting(#person: String) -> (greeting: String, language: String) {
    let language = "English"
    let greeting = "Hello \(person)"

    return(greeting, language)
}
var result = greeting(person: "Tom")
println("\(result.language)") 

2 Answers

Jhoan Arango
Jhoan Arango
14,575 Points

Hello :

Try this :

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

    return (greeting, language) // this is more clean than (greeting: greeting, language: language)
}

//var needs to be outside (this is for the second part of the challenge)
var result = greeting("Tom")

println (result.language)  // this is for the last part of the challenge

as you can tell you had your variable return inside the function, it needs to be outside of it. Also, the return just needs to call the greeting and language.

Greg Kaleka
Greg Kaleka
39,019 Points

Jhoan is close, but he's got a couple extra lines of code. In a later challenge you'll need result.language, but never result.greeting.

All that was wrong with your original code is you set your variable inside your function definition.

Here's all the code you need:

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

var result=greeting("Tom")