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 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")