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 trialTim Foster
1,331 PointsI think my code is right, but it's not working (iOS/Dev/Swift/tuples). Any thoughts?
The challenge is to create a variable named result and assign it to the tuple return values of the function, and the challenge notes that I should pass the string "Tom" to the function. I wrote:
var result = greeting("Tom")
but the code is rejected. This code works in Xcode. Am I reading the question incorrectly?
Thanks
func greeting(person: String) -> (language: String, greeting: String) {
let language = "English"
let greeting = "Hello \(person)"
return (language, greeting)
}
var result = greeting("Tom")
3 Answers
Stone Preston
42,016 Pointstask 1 states: Make sure to name each item in the tuple: greeting and language.
so, while it let you pass the first task, it seems like it expects greeting to come first, then language. modify your code so that greeting is first and language is second in the tuple:
func greeting(person: String) -> (greeting: String, language: String) {
let language = "English"
let greeting = "Hello \(person)"
return (greeting, language)
}
var result = greeting("Tom")
danieldraper2
2,082 PointsHi Tim,
You problem is with the ordering of your return statement variables. I have tested this theory with the question as well. You are correct in that your code works in Xcode but not in Treehouse.
Cheers, Daniel.
Tim Foster
1,331 PointsThanks! This worked.
Tim Foster
1,331 PointsThanks to you both--got it working with your help!
Tim