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

Tim Nicholson
Tim Nicholson
1,131 Points

I am completing a tuple task and cant see what is wrong with my code

I am completing part 1 of 3 of the tuple challenge and cant see where I am going wrong

tuples.swift
func greeting(person: String) ->(greeting: String, langauge: String) {

    var result = ("Hello \(person)", "English")

    return result
}

1 Answer

Jhoan Arango
Jhoan Arango
14,575 Points

Hello:

After looking at the challenge, I noticed that you change a few things from there.

Challenge says:

+Currently our greeting function only returns a single value. 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 we have to create a tuple as a return type. Then inside the body of the function we return the tuple itself.

                                      // This is the tuple
func greeting(person: String) -> (greeting: String, language: String) {
    let language = "English"
    let greeting = "Hello \(person)"

    return (greeting, language) // Return the tuple
}

Hope you understand a bit more. :)

Good luck