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

Barnabás Makkay
Barnabás Makkay
6,661 Points

I checked my code in a Swift Playground and it seems OK, but when I click "Check Work" the challenge doesn't accept it.

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

(Code attached)

tuples.swift
func greeting(person: String) -> (language: String,greeting: String) {
    return ("English","Hello \(person)")
}
var result = greeting("Tom")
Ferdinand Eugenio
Ferdinand Eugenio
555 Points

We have the same code I though it's just me. I don't understand the challenge here.

Barnabás Makkay
Barnabás Makkay
6,661 Points

I think it might be a defect so I also reported it to the Treehouse Team.
I'll try not to forget and post the reply here.

Ferdinand Eugenio
Ferdinand Eugenio
555 Points

Hi Makkay! I hope you doing great fond the solution for this. in the "return (language, greeting)" part we should turn around the language and greeting. so it look like this. " return (greeting, language). it's crazy!

Mine works in Xcode, but not in Treehouse.

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

    return (language, greeting)
}

var result = greeting("Tom")
Barnabás Makkay
Barnabás Makkay
6,661 Points

Change the keyword to let before result (let result = …). For me that did the trick.

1 Answer

Barnabás Makkay
Barnabás Makkay
6,661 Points

let instead of var ! ! !

Guys I solved my problem finally! Here's how:
Though the challenge asked me to create a "variable" (I assumed var), it turned out that it was waiting for a constant (let). As soon as I changed just this little thing in my code it was accepted. I sent a feedback to them about it. Hope this discovery will help you too :).

I don't really know how could I mark this post solved if you tell me how I will do.