Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Swift Functions and Optionals Functions Syntax and Parameters

Call the function greeting and pass it the string "Tom"

i don't know what to do, PLEASE someone help me!

parameters.swift
func greeting ("Tom") {
    println("Hello \(Tom)")
}

1 Answer

What you need to do is you need to give the function a named parameter. it's a template for data that is entered into the funciton.

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

so then when you envoke the function, you pass it a name that will be represented by the variable name inside your function like so

greeting("Tom")

Hope this helps.

thank you, i finally understand it now, thanks :)

just 1 question, where do i put "greeting("Tom")"?

So you are defining a function that you want to use by calling greeting("Tom") so you would want to add that line of code after you define the function outside of the braces like so.

//Defining the function
func greeting(name: String) {
  println("Hello \(name)")
}

//envoking the function.
greeting("Tom")