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 trialAdrian Baquero
4,446 PointsWhy won't this work in editor but will in xCode?
I don't understand why it works in xCode but not in the browser editor.
My code when written in xCode sure seems to assign the tuple to "result", as evidenced by accessing result.0 and result.1 and getting "English" and "Hello Tom" respectively as results. Am i missing something here?
func greeting(person: String) -> (language: String, greeting: String) {
let language = "English"
let greeting = "Hello \(person)"
return (language, greeting)
}
let result = greeting("Tom")
2 Answers
Stone Preston
42,016 Pointstask 1 states Make sure to name each item in the tuple: greeting and language. We will print them out in the next task.
it expects greeting to the be the first member in the tuple so change your return type/value around so that greeting is first, then language:
func greeting(person: String) -> (greeting: String, language: String) {
let language = "English"
let greeting = "Hello \(person)"
return (greeting, language)
}
let result = greeting("Tom")
Thomas Skjelstad
11,541 PointsI haven't explored swift that much. But it seems like you are missing let person = "" in your code. Am i wrong?
Stone Preston
42,016 Pointsperson is the parameter. it does not need to be defined in the function body since its value is passed in as an argument when the function is called
Adrian Baquero
4,446 PointsAdrian Baquero
4,446 PointsOk, I see how having them flipped could cause the checker to say "Wrong!". But I don't think the task description or the error make it clear what the problem is. After all, I DID name both items using the required names, just not in the (unspecified) order the checker was looking for.