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

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,021 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")