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 trialDavid Yoon
581 Points'String' is not convertible to '(greeting: String, language: String)' return language
I get this error. Is there any way I can resolve this??
swift_lint.swift:11:12: error: 'String' is not convertible to '(greeting: String, language: String)' return greeting ^ swift_lint.swift:12:12: error: 'String' is not convertible to '(greeting: String, language: String)' return language
func greeting(person: String) -> (greeting: String, language: String) {
let language = "English"
let greeting = "Hello \(person)"
return greeting
return language
}
David Yoon
581 PointsThank you so much!
2 Answers
kjvswift93
13,515 PointsThis is how your code should look:
func greeting(person: String) -> (greeting: String, language: String) {
let language = "English"
let greeting = "Hello \(person)"
return (language, greeting)
}
You have an incorrect return statement. The compiler doesn't understand why you are making two separate return statements that do not match the return type for the greeting function.
Emily Zhao
2,581 PointsWhy did we have to identify greeting in (greeting: String) and language in (language: String) in line 1?
I rewatched the video and the instructor didn't talk about this. He has func searchNames (#name: String) -> (Bool, String).
Using the same logic, shouldn't it be func searchNames(#name: String) -> (found: Bool, found: String)?
Thanks in advance!
Richard Robinson
5,373 PointsRichard Robinson
5,373 PointsDavid,
Because you are returning a tuple, your return statement needs to be in compound form.
Try using this syntax to replace your two, separate return statements:
"return (greeting, language)"