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

I can't pass this task, I don't understand what I'm doing wrong.

It says "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 a string "Tom" then the return string would be: "Hello Tom".

This task is found in the iOS Development with Swift-Swift Functions & Optionals- Function Return Types

Can you copy and paste the code it gives you and what you have so far?

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

This is how you start off with func greeting(person: String) { println("Hello (person)") }

and the other comment is what I have done so far

3 Answers

Maybe something like?

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

I'm not very familiar with swift but I think you just need to add a backslash

println("Hello \(greeting(person))")

I was been stuck on this question for a long time, thanks a lot Victor, appreciate it!