Optional closures in Swift 4

Viewed 3199

I need a closure method executed on demand.

In Swift 3 I used to do something like this:

// Declare closure
var checksPerformed: ((Void) -> Void)? // Declaration

// Call when needed
checksPerformed?() 

//Only executes when checksPerformed is called
checksPerformed = { _ in 
    // do stuff here
}

In Swift 4 this is no longer the case.

enter image description here

And after fixing this warning nothing works as before. What is the new way of doing this?

If I'm updating the declaration to: var checksPerformed: (() -> ())? I'm getting

enter image description here

2 Answers
Related