0

I'm referring to an example in the Apple 3.1 Swift Tour:

func greet(_ person: String, on day: String) -> String {
    return "Hello \(person), today is \(day)."
}
greet("John", on: "Wednesday")

In the function head it states "on day" whereas in the return statement, the code only refers to "day" and finally, when calling the function, it only assigns a value to "on". Why "on day" in the first place? Why not just "day"?

dfrib
  • 70,367
  • 12
  • 127
  • 192
paperclip
  • 21
  • 5
  • 1
    See also the section [Functions - Function Argument Labels and Parameter Names](https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Functions.html) in the Swift Language Guide. – dfrib Apr 22 '17 at 13:13
  • `day` is the name of the 2nd parameter in the `greet` function. `on` is the name of the 2nd parameter when you call the function `greet`. They are the same variables, just different names according to the scope. – Toldy Apr 22 '17 at 13:37

0 Answers0