first, what is the name of the external parameter.
To put it simply, an external parameter name is to add a specific name to the method's arguments before it is invoked, in order to facilitate reading code and improve maintenance efficiency.
in the latest Xcode, the properties and usages of the external parameter names are as follows Nature:
A function can have both a local name (used internally) and an external name (used when calling a function), and the method's arguments are similar, although the default behavior of the method and function's local name and external name is not the same
The default for Swift is to give the first parameter name a local parameter name, and the second and subsequent parameter local parameter names and external parameter names default to the same usage example:
In other languages, if we define a method in this way:
We generally call this:
And there's a mistake in Swift's wording,
As defined above, the system has the following error:
You should call this:
The so-called argument labels is the name of the external parameter.
I was overwhelmed when I first touched this thing because I didn't show the external parameter name, but the system added the default name of the external parameter that is the same as the formal parameter. But the strange thing is that the first parameter x does not default to the name of the external parameter. The reason is:
The default for Swift is to give the first parameter name a local parameter name, and the second and subsequent parameter local parameter names and external parameter names are the same by default.
To modify the external parameter name of a method
Sometimes it is useful to provide an external parameter name for the first argument of the method, which can be displayed before the parameter by adding a # number
If you do not want to provide an external parameter name for the second and subsequent parameters of the method, use the underscore (_) as the explicit external name for the parameter.
1, for example, you want to call the method like this:
You should define a method like this:
2, and for example, you want to call the method like this:
You should define a method like this:
3, or show other external parameter names
This definition:
This call: