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

I can't figure out objective 3:

Challenge is: Using the println statement, print out the value of the language element from the result tuple.

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

          return (greeting ,language)
           }

            var result = greeting("Tom")
            println()

6 Answers

Kieran Tross
Kieran Tross
8,266 Points

that doesn't work. i think you have to pass more result options within the result parameter.

Kieran Tross
Kieran Tross
8,266 Points

you have to pass the "println(language) within the greeting function. This has to be applied within the greeting function scope.

I don't think that's what they want. I think they expect something like:

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

    return (greeting, language)
}

let result = greeting("Tom")
println(result.language)
Kieran Tross
Kieran Tross
8,266 Points

no that didn't work. You have to apply the "println(language) above the first return statement.

Kieran Tross
Kieran Tross
8,266 Points

Did you try what i stated? The below works.

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

return (greeting, language)

}

var result = greeting("Tom")

Jhoan Arango
Jhoan Arango
14,575 Points

There seems to be an error in this challenge. But to pass the challenge it has to be this way. Even tho this is not correct.

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

    return (greeting, language)  // the error seems to be here
}

var result = greeting("Tom”)  

println(result.greeting)

The correct way of doing it is like this, but it won’t pass the challenge for some reason.

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

    return (language, greeting) // Corrected
}

var result = greeting("Tom")

result.greeting // will print “Hello Tom”
result.language // will print “English"

println(result.language)