swift:missing argument label ' xxx ' in the call

Source: Internet
Author: User

Http://www.cnblogs.com/breezemist/p/4326644.html

Today in the use of Swift found that the write Func always required to write out the second parameter of the external variable name, do not understand, feel and the book said the function is not the same, checked, and finally found the reason: written in the class inside the function called method, is a special functoin, the system will automatically fill in the external variable name, see the following connection Http://stackoverflow.com/questions/24050844/swift-missing-argument-label-xxx-in-call

To prevent the connection from failing, the interception section reads as follows:

One possible reason is this it is actually a method. Methods is very sneaky, they look just like regular functions, but they don's act the same, let's look at this:

func funFunction(someArg: Int, someOtherArg: Int) {    println("funFunction: \(someArg) : \(someOtherArg)")}// No external parameterfunFunction(1, 4)func externalParamFunction(externalOne internalOne: Int, externalTwo internalTwo: Int) {    println("externalParamFunction: \(internalOne) : \(internalTwo)")}// Requires external parametersexternalParamFunction(externalOne: 1, externalTwo: 4)func externalInternalShared(#paramOne: Int, #paramTwo: Int) {    println("externalInternalShared: \(paramOne) : \(paramTwo)")}// The ‘#‘ basically says, you want your internal and external names to be the sameexternalInternalShared(paramOne: 1, paramTwo: 4)

Now here's the fun part, declare a function inside of a class and it's no longer a function ... it s a method

class SomeClass {    func someClassFunctionWithParamOne(paramOne: Int, paramTwo: Int) {        println("someClassFunction: \(paramOne) : \(paramTwo)")    }}var someInstance = SomeClass()someInstance.someClassFunctionWithParamOne(1, paramTwo: 4)

This was part of the design of behavior for methods

Apple Docs:

Specifically, Swift gives the first parameter name in a method a local parameter name by default, and gives the second and Subsequent parameter names both local and external parameter by default. This convention matches the typical naming and calling convention you'll be familiar with from writing objective-c Metho DS, and makes for expressive method calls without the need to qualify your parameter names.

swift:missing argument label ' xxx ' in the call

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.