External Parameter Name in Swift
External Parameter Name
In Swift, an external parameter name is the name used when calling a function, method, or initializer. It provides clarity at the call site, making the code more readable and self-documenting. It is also known as an argument label. It has the following syntax:
func type1(name: String, lastname: String){
// body
}
Example:
func type1(name: String, lastname: String){
print("Welcome \(name) \(lastname)!")
}
type1(name: "Talha", lastname: "Saygili")
Customizing External Parameter Names
You can explicitly define an external parameter name that is different from the internal parameter name by placing the external name before the internal name, separated by a space, in the function definition:
func sayHello(to name: String) { // 'to' is the external name, 'name' is the internal name
print("Hello, \(name)!")
}
sayHello(to: "Bob") // You must use 'to' when calling the function