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