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 Optionals Review: Functions

what is the # when declaring a function and prefixing the parameter(s) with # ? ex func test(#testVar:String)

I forgot and I keep seeing functions with parameters declared like this in the tutorials. What is # for again?

1 Answer

Michael Reining
Michael Reining
10,101 Points

The # value has been removed from Swift when declaring functions. In the past, you used # so that the outside name when calling the function would be the same as the inside name of the variable.

Here is an example if you want the names to be different.

func test(outsideName insideName:String) {
        print(insideName)
}

test(outsideName: "My String")

If you do not specify a name for the argument in the function, then it gets skipped when calling the function.

func test(variableName:String) {
        print(variableName)
}

test("My String")

I hope that helps,

Mike

PS: Thanks to the awesome resources on Team Treehouse, I just launched my first app. :-)

Code! Learn how to program with Swift