Swift 3 first parameter names

前端 未结 5 830
慢半拍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:52

    Yes, this is right. Swift is fixing a language inconsistency this way (this was always required for initializers).

    If you don't want to use the external parameter name, just remove it explicitly:

    func frobnicate(_ runcible: String) { 
        print("Frobnicate: \(runcible)") 
    }
    

    You can read the full rationale in Swift Evolution 0046

提交回复
热议问题