3 ms·
Is there a parse-time reason that they required the "_" syntax, rather than simply: func greet(greeting: String, personName: String) { print("\(gre
by derefr 10y ago
Is there a parse-time reason that they required the "_" syntax, rather than simply:
func greet(greeting: String, personName: String) {
print("\(greeting), \(personName)!")
}
- thramp 10y agoIt's a side effect of labeled arguments. The caller would use the function greet as `greet(greeting: "Hello", personName: "Alice")`.
- masklinn 10y agoThe reason is that named parameters is the default, so in your case greeting and personName are both "internal" and "external" names. "_ greeting" sets the external name to _ (aka positional) and the internal name to "greeting" instead.