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

iOS Development with Swift - Tuples - Challenge 2 / 3?

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

I think I'm doing everything right, but I'm getting the following error message:

"Bummer! Your result variable has the wrong value in it. Check the task instructions again."

Can someone please lend me another set of eyes and let me know what I'm doing wrong?

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

    return (language:language, greeting:greeting) 
}

var result = greeting("Tom")

4 Answers

Hey, Adam,

The code you're looking for is:

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

    return (greeting, language)
}
var result = greeting("Tom")

You only have to specify once what you want to return inside the return function :)

Thank you very much!

William -

I have used exactly this and it works in Xcode. However, task 2 does not like the result. Please, help?

Hey, Anthony.

It does work for me. Make sure you haven't misspelled anything ;)

I'll write here what I use to achieving the challenge:

Task 1:

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

    return (greeting, language)
}

Task 2:

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

    return (greeting, language)
}

var result = greeting("Tom")

Task 3:

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

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

Good luck :)

William - Thanks for the quick response! Here is what I am using:

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

    return (greeting, language)
}

var result = greeting("Tom")

Haven't been able to get to task 3.

Found it!

let language= "English"

You've got a space between " and English :D

Good lord! I'm going blind! Thanks for the help!!!!

You're welcome! And don't worry: it happens to all of us ;)