What are 3 items in a Swift method parameter for?

前端 未结 4 1373
一个人的身影
一个人的身影 2020-12-12 02:49

Example:

mutating func moveByX(deltaX: Double, y deltaY: Double)

The first parameter takes a Double and saves it in that method scope as

4条回答
  •  情书的邮戳
    2020-12-12 03:27

    deltaX and deltaY are the parameter names when you are writing the function. However, when you call the function it will be called as movebyX(val, y: val) where val is replaced by the Double you are passing into the function. The y in the middle is essentially to help the readability of the function when it is called and is common practice in swift to make your code as readable as possible (the person calling your function can easily tell what each parameter is without looking at the function header).

提交回复
热议问题