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

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

My code no compiler errors but I still can't advance.

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


    return language

}


var result = greeting("Tom") 

4 Answers

Stepan Ulyanin
Stepan Ulyanin
11,318 Points

Hi, you are returning only one value not 2 as a tuple, you need to specify the tuple at your return statement:

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

    return (language, greeting)
}

var result = greeting("Tom")
JT Keller
JT Keller
12,731 Points

I'm having the same issue and I just copy and pasted your code and it fails as well. I believe you're wrong as the OP's answer is technically returning a tuple.

I tried each of these and they work great in the compiler and the console output is correct as well. Not sure what is wrong.

//func greeting(person: String) -> (language: String, greeting: String) {
//    
//    let response = (language: "English", greeting: "Hello \(person)")
//    return response
//}
//
//let result3 = greeting("Tom")
//println(greeting("Tom"))
//result3.greeting
//result3.language

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

    let language = "English"
    let greeting = "Hello\(person)"
    return (language, greeting)
}

let result1 = greeting("Tom")
JT Keller
JT Keller
12,731 Points

But this works... The exercise didn't state anything about a named parameter as it should if this is the requirement for the code to pass the checks.

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

    return (greeting, language)
}
var result = greeting(person: "Tom")
Rick Matsumoto
Rick Matsumoto
2,547 Points

I think greeting needs to be a variable rather than a constant, but otherwise agree that this code compiles fine and still does not pass the code challenge. The message I get is "Your result variable has the wrong value in it." I'm stumped!

Rick Matsumoto
Rick Matsumoto
2,547 Points

Still not sure I understand what happened, but this passes the code challenge.

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

    return (greeting,language)
}

var result = greeting("Tom")
Sam Donald
Sam Donald
36,305 Points

You need to specify person. so.... var result = greeting(person: "Tom")