Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
167 views
in Technique[技术] by (71.8m points)

Changes in terminology for Swift function parameter labels

Swift provides the ability to give both an internal and external name/label for parameters of functions. But lately Apple seems to have resorted to only saying "Argument" and "Parameter" names/labels and dropped the use of internal/external to describe these things.

In the Swift documents, and WWDC videos, there are a few unclear efforts to describe the difference between a function's parameters and arguments, without referring to these as the outward facing or internal, such as:

Each function parameter has both an argument label and a parameter name. The argument label is used when calling the function; each argument is written in the function call with its argument label before it. The parameter name is used in the implementation of the function. By default, parameters use their parameter name as their argument label.

Imagine a jump() function.

Internally, the names of "when" and "height" might be different, and these are the internal names. External and internal don't seem to be at all confusing, other than the ordering in the Function Definition and then Declaration:

 func jump(_ who: String, whenToJump when: Float, howHigh height: Int){
        // wait for whenToJump
       // adjust who.y by howHigh
    )

Which of these is a parameter, in the sense Apple is referring to them, and which is an argument?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Everything is described in detail in the section Function Argument Labels and Parameter Names

in The Swift Programming Language (Swift 3)

Briefly, the differences between Swift 2 and Swift 3 are

  • "External name" (Swift 2) is now "Function Argument Label" (Swift 3)
  • "Internal name" (Swift 2) is now "Parameter Name" (Swift 3)
  • In (Swift 2) the first parameter is _ name (internal, but no external) by default
  • In (Swift 3) the first parameter is name name (function argument label and parameter name) by default.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...