I was reading the apple doc when I fell upon this piece of syntax :
struct Point {
var x = 0.0, y = 0.0
mutating func moveBy(x deltaX: Double, y deltaY:
Short answer: first argument label is for external caller, second one for local in-method use.
func moveBy(x deltaX: Double, y deltaY: Double)
when calling looks following: moveBy(x: 1, y: 1)
, but inside the method deltaX
and deltaY
labels are used.
This naming style is not necessary, you can declare the method func moveBy(x: Double, y: Double)
so x
and y
will be used inside the method.
To support legacy style, so from caller scope your method looks like moveBy(1, 1)
, you should place _
as first argument label: func moveBy(_ deltaX: Double, _ deltaY: Double)
. Such declarations are used in CocoaTouch to support legacy obj-c interface (ex. func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool
).