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

'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

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

    return greeting
    return language
}

David,

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)"

Thank you so much!

2 Answers

This 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
Emily Zhao
2,581 Points

Why 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!