0

Why am I getting this error when the arguments for the function are the same as what's being passed?

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

2 Answers 2

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) } 
Sign up to request clarification or add additional context in comments.

3 Comments

That works, thanks. I've got to try to remember those weird _'s
Welcome, Happy to help
@pguardiario The "weird" _ are not actually needed. They are optional.
0

The line (with the mysterious extra { at the end):

self.foo(path, arguments, true){ 

needs to be:

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

The use of self. is optional.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.