Swift错误:通话中有其他参数

时间:2018-06-21 04:02:36

标签: swift

当函数的参数与要传递的参数相同时,为什么会出现此错误?

class ViewController: NSViewController {

   func foo(path: String, arguments: [String], showOutput: Bool) -> Void {
   }

    @IBAction func a1(_ sender: NSButton) {
        let path = "/sbin/ping"
        let arguments = ["-c", "5", "google.com"]
        self.foo(path, arguments, true){ // I'm getting extra argument in call for true
    }
}

2 个答案:

答案 0 :(得分:1)

func foo(_ path: String,_ arguments: [String],_ showOutput: Bool) -> Void {
    /// Prerform task here whic you want to perform while calling this
    /// function or task with those Paramaters
}

@IBAction func a1(_ sender: NSButton) {
    let path = "/sbin/ping"
    let arguments = ["-c", "5", "google.com"]

    /// It is just a normal Function that accepts parameteres and
    /// Preform requred Task
    self.foo(path, arguments, true)
}

答案 1 :(得分:0)

该行(末尾有神秘的额外{

self.foo(path, arguments, true){ 

需要是:

self.foo(path: path, arguments: arguments, showOutput: true)

使用self.是可选的。