Swift : missing argument label 'xxx' in call

前端 未结 6 773
-上瘾入骨i
-上瘾入骨i 2020-12-04 15:01
func say(name:String, msg:String) {
    println(\"\\(name) say \\(msg)\")
}

say(\"Henry\",\"Hi,Swift\")  <---- error because missing argument label \'msg\' in ca         


        
6条回答
  •  [愿得一人]
    2020-12-04 15:59

    This is simply an influence of the Objective-C language. When calling a method, the first parameter of a method does not need to be explicitly labelled (as in Objective-C it is effectively 'labelled' by the name of the method). However all following parameters DO need a name to identify them. They may also take an (optional) local name for use inside the method itself (see Jiaaro's link in the comments above).

提交回复
热议问题