I have been migrating my project code to Swift 4.0.
I am facing an issue with closures. In the below code snippet:
class ViewController: UIViewController
{
var completionClosure: ((Void)->(Void))? //WARNING: When calling this function in Swift 4 or later, you must pass a '()' tuple; did you mean for the input type to be '()'?
override func viewDidLoad()
{
super.viewDidLoad()
self.completionClosure = { //ERROR: Cannot assign value of type '() -> ()' to type '((Void) -> (Void))?'
print("This is a closure.")
}
}
}
The above code worked perfectly in Swift 3.2. And in Swift 4.0, it is giving me these warnings and errors.
I understand there is no point in using Void
if the closure doesn't contain any input arguments and return type
, i.e the closure could have been written like:
var completionClosure: (()->())?
But still, why is it giving me the error? Isn't Void
same as No Value
?
Are there any changes introduced in the concept of closures since Swift 4.0?