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

Sara Grim
Sara Grim
5,285 Points

I am having problems with the Return Type challenge. Could someone help me?

Swift Return type challenge:

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

I seem to be all mixed up on this!

You've done everything right nearly what you need to do is remove the println function and just return the string and the variable using interpolation like so

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

1 Answer

Adam Debbagh
Adam Debbagh
31,216 Points

greeting function has one parameter of type String named "person". person can only be used from within the greeting function (local scope). the greeting function returns a string. we know that from the little arrow symbol (->String). you could write something like :

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

To call the greeting function. simply type :  ```greeting("Tom")  ``` 
To print it out , you can use println() function like this :
  ```println(greeting("tom"))  ```
Sara Grim
Sara Grim
5,285 Points

Thank you Adam! It totally works now. I needed to also delete my previous example using func greeting that was throwing it all off as well.