In Swift each function parameter can have both argument label and a parameter name.
argument label: used in function callparameter name: used inside the function definition
By default, parameters use their parameter name as their argument label.
These are the possible function declarations that can be used in swift:
Case 1: parameter name is same as the argument label
func greet (person: String, day: String) -> String {
return "Hello \(person) on \(day)"
}
Function Call: greet(person: "John", day: "23")
Case 2: different parameter name and argument label
func greet (person person: String, on day: String) -> String {
return "Hello \(person) on \(day)"
}
Function Call: greet(person: "John", on: "23")
Case 3: using _ as argument label
func greet (_ person: String, _ day: String) -> String {
return "Hello \(person) on \(day)"
}
Function Call: greet("John", "23")
For more on how function parameters work, you can refer to: https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Functions.html
Let me know if you still face any issues.
2
solved Swift 4 custom argument labels – required? [closed]