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

Nkosi Ndlovu
Nkosi Ndlovu
9,652 Points

Named Parameters Swift

Something is wrong with my code but I'm not sure what it is exactly. I appreciate any help with this. Thanks

func greeting(#person: String) ->String{
    let greeting = "Hello \(person)"
    return greeting
}
greeting("Jerry")

2 Answers

Stone Preston
Stone Preston
42,016 Points

since you provided an external parameter name, the name must be included in the function call. also you changed the function in the challenge. its not supposed to return anything. the challenge initially shows:

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

so just add a # to the parameter to provide an external parameter of the same name. then call it and use the external name in the function call

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

greeting(person: "Jerry")

the swift eBook states:

If you provide an external parameter name for a parameter, that external name must always be used when you call the function.