Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,843 Points

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

1 Answer

Jhoan Arango
Jhoan Arango
14,547 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,547 Points

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