swift - 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
}
}
解决方案
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)
}
推荐阅读
- apache-spark - Spark operator vs spark submit - 如何选择使用哪一个?
- entity-framework-core - 将表值参数传递给 EF Core 查询
- javascript - 另一个项目中的 Firebase 身份验证
- typescript - 使用动态键在 Typescript 中动态创建对象,无需将类型扩展为 { [key: string]: T }
- blazor - 无法使用子目录直接访问 Azure 静态应用中托管的 Blazor WASM
- calculator - 需要创建 GPA 计算器才能在命令行中运行
- dependency-injection - 控制反转和深度依赖
- docker - 有谁知道如何通过 Puppet manifest 安装 docker 和 docker-compose
- c - 指针非法访问 PIC32 上的数组
- java - 如何使用 CardLayout 将 JPanel 从另一个类添加到面板?