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 Functions Function Return Types

Marie Jose Lemiere
Marie Jose Lemiere
872 Points

String is not convertible to String

I get the message : "String' is not convertible to 'String'" I can't find a way around...

returns.swift
func greeting(person: String) -> String {
   return greeting
}

1 Answer

The problem here is you're trying to return the function name as a string, so the compiler is getting into an endless circular loop. Just changing the return statement to anything else should work as in the example provided next:

func greeting(person: String) -> String {
    return "Hello " + person
}

greeting("Pedro")
Marie Jose Lemiere
Marie Jose Lemiere
872 Points

Thank you Pedro ! It helps me a lot.