9.8 Declaring Default Function Parameters
Swift provides the ability to designate a default parameter value to be used in the event that the value is not provided as an argument when the function is called. This simply involves assigning the default value to the parameter when the function is declared. Swift also provides a default external name based on the local parameter name for defaulted parameters (unless one is already provided) which must then be used when calling the function.
To see default parameters in action the buildMessageFor function will be modified so that the string “Customer” is used as a default in the event that a customer name is not passed through as an argument:
func buildMessageFor(_ name: String = "Customer", count: Int ) -> String
{
return ("\(name), you are customer number \(count)")
}
The function can now be called without passing through a name argument:
let message = buildMessageFor...