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!

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 Syntax and Parameters

What do i hav eto do on, "Call the function greeting and pass it the string "Tom".?

i want it to understanding this line of code for this community to help me please because i wan to go to other parts of the course I'm taking.

func greeting(name: "Tom") {
    println("Hello \(greeting)")

1 Answer

Jennifer Nordell
Jennifer Nordell
Treehouse Teacher

Hi there! Keep in mind that most challenges will require that you build upon the code that you already had. So the parameter you're accepting shouldn't have changed. It should be named person and of type String. So let's take a look:

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


Here we have a function named greeting. It's going to accept one piece of data being sent to it by another piece of code. When that data gets there it is of type String and its name is person. It now works just like any other variable. We can now print out a line with with "Hello" and then whatever was sent into person. Now outside of the function we call it. And we do this simply by stating the name of the function and then putting what we want to pass inside the parentheses. So we call greeting and then send in "Tom". This is equivalent to saying person = "Tom". The function will then print a line with "Hello Tom". Hope this clarifies things! :sparkles: