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

Utsav Chatterjee
Utsav Chatterjee
627 Points

I have written the code correctly and it works on Xcode too.. but i get an error here.

The change I made is func greeting(#person: String)

parameters.swift
func greeting(#person: String) {
    println("Hello")
}

2 Answers

Nick Kohrn
Nick Kohrn
36,935 Points

By default, the first parameter name in a function is a local parameter, which does not need the hash mark.

However, any subsequent parameters can accept a hash mark if it makes sense for the local and external parameter names to be the same.

Damien Watson
Damien Watson
27,419 Points

There shouldn't be a hash tag '#' before the variable:

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