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

How do i have to type, I'm confused!!!!

please help., i tried many times but still don know what to type, please help.

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

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! I'm not sure exactly which step you're stuck on, but I'll show my solution and then walk you through it:

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

Here we define a function named greeting. This function accepts a parameter named person of type String. Next we print out the line with "Hello". At this point it's going to look up the name that was sent into the person parameter and put it in that spot. So if we sent in "Jennifer", it will print out "Hello Jennifer". Hope this helps! :sparkles:

ok thank you :)

Also, some other helpful tips for writing better functions in the future is that they always need a name, the left slot is for the input, and the right slot is for the output. Not all functions need parameters or return types, if not, the empty parameter is an empty set of parenthesis and return type is nothing more than an opening brace after the return type. I hope this helps!