Swift 3 first parameter names

前端 未结 5 821
慢半拍i
慢半拍i 2020-11-27 20:12

In Swift 2, it appears that the first parameter name is not always required when calling a function. Now in Swift 3, the first parameter name is required when calling the f

5条回答
  •  遥遥无期
    2020-11-27 20:47

    The reason you want labels for parameters is so other code can supply parameters in any order.

    Without labels, when you call the function the parameters are anonymous and you cannot be certain if you have supplied them in the wrong order.

    Place labels in front of the parameters and code tools can do a much better job at catching errors us humans put in.

    The underscore is just a way to cope with the transition from legacy code; method names including an Implicit first parameter. You should change any underscores that migration adds to your code to an explicit parameter label. You know it makes sense.

提交回复
热议问题