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

Mia Pivirotto
Mia Pivirotto
5,557 Points

How do you return a function that has a variable without using the println function to define the variable?

I'm trying to do the challenge for the function return and cannot figure out how to get my function to print out Hello Tom.

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

1 Answer

Hello Mia,

You almost have it.

func greeting(person: String) {
    println("Hello \(person)")
}

greeting("Mia")

Try placing the above code in playground to see it in action!

Mia Pivirotto
Mia Pivirotto
5,557 Points

I'm still getting an error message. The point of the exercise is to take the println out of the code and replace it with return, but I must be getting the syntax wrong with the return. I have this:

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

Mia, You don't need to add the greeting function it self.

only the following:

func greeting(person: String) {
    println("Hello \(person)")
}