I said in the previous article, give a function name is best to let a person through the name of the approximate function of the function, rather than let people read the internal code to know what your function is, everyone is a programmer, you do not want to next person to answer your code when greeting you xxx What, it also has a certain connection with the norms, This time, let's just say that the parameter name of the function
In fact, the function parameters are externally named and locally named, external naming is the name of the external call function, local naming refers to the function block used to access the use of, in my personal understanding is also a supplement, which is my personal preference for swift, the equivalent of a long name split, External calls maybe you're still ambiguous, but when you see the function, and you find that there are local names, is it better to understand the function function, because you don't want to write a long name for the external call, say so much, a simple sentence, that is, the external name is to provide you with the call, Local name is used inside the function, no, for example
SomeFunction (1, secondparametername:2) } func someFunction (Firstparametername:int, Secondparametername: Int) { }
The external function name of the first parameter is ignored, all parameters have a unique local name, but can have a common external naming
The above is just a brief introduction, let's talk about how to specify the external parameters of the name it
The external parameter name is written in front of the local parameter name, separated by a space. Once you provide an external name for a parameter, an external name is always present when the function is called.
Print (To: "SayHello", and: "I") } func SayHello (to Person:string, and anotherperson:string), String { return "hello,\ (person) and \ (Anotherperson)" }
Does it feel like the code is more readable and clear?
(ii) ignore external parameter names
Maybe you're thinking, I don't want to see the name of the external parameter when I call the function, can I ignore it, the answer is of course, then we could use "_" instead of explicitly declaring the external parameter name, such as:
SomeFunction (1, 2) } func someFunction (Firstparametername:int, _ Secondparametername:int) { }
This is OK, the first parameter here is not _, because he has ignored the external parameter name by default
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Parameter naming of the function of Swift learning