首页 > 解决方案 > 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
    }
}

标签: swift

解决方案


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)
}

推荐阅读