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

Swift basics return type error

Q:Modify the definition of the function named greeting to return a String and replace the println statement with a return statement. The function should return a greeting. For example, if you pass in a string "Tom" then the return string would be: "Hello Tom".

Not sure why this isn't the right answer... I can't compile the code either because it shows an error message.

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

You might need to refresh your browser.

Did that, also restarted my computer, tried using a different network... but im only stuck in this question the other ones work.

Did you try copy and pasting my code? If you typed it manually there might be a syntax error. Also, have you tried using a different browser such as Chrome?

right now im using safari, but I've used chrome too

Sorry, I don't know what the problem might be. Maybe your internet connection is affected? Might want to refresh the router.

2 Answers

Leonardo,

Replace the print statement with a return statement and then call the function.

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

this didn't work either, im still getting: Oh no! There was a communication problem.

If you continue experiencing problems, please contact support at help@teamtreehouse.com.

I've already contacted them but I've been told to post my code here.

func greeting(person: String) -> String {

return ("Hello (person)")

}

// There needs to be a backslash before (person)

mine has a backslash before (person)