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

I have no idea how to solve this. I've tried everything.

I'm sure I am making a fundamental mistake, please help me correct this.

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

println("Hello \(greeting(Tom))")

3 Answers

Vittorio Somaschini
Vittorio Somaschini
33,371 Points

So this task is basically 2 different tasks, the first one, where we need to declare that the output will be a String (and you did this correctly).

The second part asks you to change the print statement into a return statement. We do this by changing the keyword on the last line inside the function. No code will need to be outside the function here.

Let me know if this works.

Vittorio Somaschini
Vittorio Somaschini
33,371 Points

Hello Andrew.

You are not supposed to print anything here, just make the function return the full string and you will be ok.

Vittorio

I don't know how to do that. What exactly am I supposed to write?

Max Hirsh
Max Hirsh
16,773 Points

Hi Andrew, so in this challenge, the goal is to modify the function to return the string "Hello (person)" with the proper input string added in The way you have the function modified at the moment is close but is only returning the input string itself. There's no need to call the "println" method so don't worry about that. Let me know if that helps.