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

It works within Xcode but I still get an error in the simulator that the result is wrong. Any suggestions?

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

return (language, greeting)

}

let result = greeting("Tom")

3 Answers

ah . found the issue. the challenge states in task 1: Modify it to return both the greeting and the language as a tuple. Make sure to name each item in the tuple: greeting and language. We will print them out in the next task. so it seems to be expecting the greeting to come first in the tuple and the language second. so flip them around in your return type and in your return value.

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

return (greeting, language)

}

var result = greeting("Tom")

Ah yes now it has accepted it as valid :-) Thanks for looking into this Stone!

Cheers!

Rick

task 2 states Create a variable named result and assign it the tuple returned from function greeting. you created a constant using let. make it a variable by using var

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

return (language, greeting)

}

var result = greeting("Tom")

Thanks Stone, for the quick (or swift) reply!

I tried using 'var' before changing it to a constant. I changed it back again by using var but it is still not accepting.. :-/

I have the same problem as Rick and can't move forward....help.

Here is the answer:

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)