First, what is the external parameter name?
Simply put, the name of an external parameter is called when a method is invoked to precede the parameters of the method with a specific name, in order to facilitate reading code, improve maintenance efficiency.
second, in the latest Xcode, the nature and usage of the external parameter name are as followsProperties:
A function can have both a local name (internal use) and an external name (used when calling a function), and the method's parameters are similar, although the default behavior of the local and external names of methods and functions is different
The first parameter name is given a local parameter name by default in Swift, and the second and subsequent parameter local parameter names and external parameter names are the same by default
Usage examples:
In other languages, if we define a method like this:
We generally call this:
And Swift is wrong in this notation,
As defined above, the system error is as follows:
This should be called:
The so-called argument labels is the name of the external parameter.
I was at a loss when I first touched this thing, because I didn't show the name of the external parameter, but the system adds the default name of the external argument that is the same as the parameter. But the strange thing is that the first parameter x does not have an external parameter name set by default.
The reasons are:
The first parameter name is given a local parameter name by default in Swift, and the second and subsequent parameter local parameter names and external parameter names are the same by default.
Modify the external parameter name of a method
Sometimes it is also useful to provide an external parameter name for the first parameter of the method, which can be displayed before the parameter by adding the # number
If you do not want to provide an external parameter name for the second and subsequent arguments of the method, use the underscore (_) as the explicit external name for the parameter.
1, for example, you want to call this method:
The method should be defined like this:
2, for example, you want to call this method:
The method should be defined like this:
3, or display other external parameter names
This defines:
This is called:
Reference page:
http://blog.csdn.net/huangchentao/article/details/32715179
Swift development experience-External parameter names