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 Parameters and Tuples Named Parameters

How do I call the greeting function and pass it the String "Jerry?"

I've done what I feel is "calling the greeting function;" however, I'm still getting a "call the greeting function" message.

Michael Hulet
Michael Hulet
47,913 Points

Could you post your code, so we can see what you did?

1 Answer

Jhoan Arango
Jhoan Arango
14,575 Points

Hello Mark:

This challenge is about creating an external parameter name.

  • An external parameter name is created to label arguments when calling a function.
  • A local parameter name is used to implement the functionality of a function.

For example:

func printName(name: String){
println("Hello my name is \(name)") 
// Here we are using the local parameter name to implement its functionality.
}

This function printName has a parameter where you can pass it an argument of type string, but it ONLY has the local parameter name, which I called it "name", and it's only being used to implement its functionality.

Therefore when you want to use ( call ) this function, you don't have to use it's local parameter name.

We would call it like this:

printName("Mark")
  • In Swift 1.2 you use the # symbol to create an external parameter name IF you are using the same as the local parameter name.
  • In Swift 2.0 the # symbol is no longer used.

Now if we give the function an external parameter name, it would look like this.

// Swift 1.2
func printName(#name: String){
println("Hello my name is \(name)")
}
// Swift 2.0
func printName(name name: String){
print("Hello my name is \(name)")
}

And to call this function, it would be like this:

printName(name:"Mark")

Hopefully this helps you pass your challenge.

Good luck

This was an all-encompassing answer. Thank you for this approach and your time Jhoan!

Jhoan Arango
Jhoan Arango
14,575 Points

You are welcome, hopefully you were able to understand and pass the challenge.