0

I'm trying to create a function that has a closure. Nothing is passed to the function, just after it finishes another function has to be called. Something like this:

  func addGradient(closure: syntax) {
(closure: _ in ("function call here")   )}

so it can be called similiar to this

addGradient(closure: "function to be called")

1 Answer 1

2

Just use the signature for the function minus any of the names:

func doIt(one: Int, two: String) -> [String] {
  …
}

Would have the closure signature of:

(Int, String) -> [String]

So yours would be:

func addGradient(closure: (Int, String) -> [String]) {
  …
}

And you can call it like this:

addGradient(closure: doIt)

One more note, a function like this:

func doAgain() {
  …
}

Has a closure signature of this:

() -> ()
Sign up to request clarification or add additional context in comments.

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.