- Configure external parameter names
Add "#" to the parameter name of the function (or method) before it can have the same local parameter name and external parameter name.
Note: In the method, the second and subsequent parameters, the default is with the internal parameters consistent with the external parameter name, only the first parameter is not, you can use the "#" symbol to force the first parameter to the local parameter name consistent with the external parameter name, but is not recommended.
(1) function
Func IncrementBy (Amount:int, #numberOfTimes: Int) {
Count + = Amount * Numberoftimes
}
Numberoftimes local parameter names (which can only be used inside functions) and external parameter names (used as tags when calling functions) are numberoftimes.
(2) method
Class Counter {
var count:int = 0
Func IncrementBy (#amount: Int, Numberoftimes:int) {
Count + = Amount * Numberoftimes
}
}
Numberoftimes default has local parameter name and external parameter name, amount does not have external parameter name, use "#" to force specify external parameter name for amount, when calling the method, the external parameter name must be used, otherwise there will be a compilation error, prompting missing parameter label.
var counter = counter ()
Counter.incrementby (Amount:4, Numberoftimes:5)
println (Counter.count)//The result is 20
Use of "#" in Swift