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

boris said
boris said
3,607 Points

I get this error when I try to run my code and i've tried many different things and I can't get it to work please help.

Can someone please help me

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

    return (greeting, language)
}



var (greeting,language) = greeting("Bob")

1 Answer

Try this:

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

   return both
}
Jhoan Arango
Jhoan Arango
14,575 Points

Hello Shannon:

Your answer is a good solution, however there is a more simple way to do this, and one that I think the challenge is expecting.

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

  return (greeting, language)
}

Again your solution is good, I am just adding an extra solution to your answer :)