Cannot Assign Value of Type '() -> Void' to Type '(() -> Void)!'

Swift 4: Cannot assign value of type '(Void) - Void' to type '(() - Void)?'

First change the type of stoppedSuccessfully from (() -> Void)? to ((Void) -> Void)?:

private var stoppedSuccessfully: ((Void) -> Void)?

Because, when you use Promise<T>, the closure type passed to success is of type (T)->Void. In your code, you are using Promise<Void>, so the type of success is (Void)->Void, not ()->Void.

Thus, your stoppedSuccessfully should be declared as Optional<(Void)->Void>, which is equivalent to ((Void)->Void)?.


And to call the closure of type (Void)->Void, you need to pass one argument of type Void. There's a literal notation of type Void, it's (), an empty tuple.

So, you can replace all success(Void())s to simply success(()).

And you can invoke stoppedSuccessfully in the similar manner:

// In a other part of the code:
self.stoppedSuccessfully?(())

Cannot assign value of type '() - Void' to type '(() - Void)!'

It seems your issue is related to this:
SE-0103

Try chaging the method header of your addButton(_:action:) to:

public func addButton(_ title:String, action:@escaping ()->Void)->SCLButton {

The diagnostic messages from new betas are so confusing and inadequate as usual, but making your property simply non-Optional var action:()->Void = {} will give you a little more useful info.

Swift 4: Cannot assign value of type '(_) - Void' to type '(() - ())?'

Because clickAction expects a parameter-less function/closure. Simply change your code to:

button.clickAction = {
action()
Sound.playSound(Sounds.Button)
}

Cannot assign value of type '() - Void' to '(() - Void)!'

Swift 3 maps Objective C NSError type to protocol Error(aka ErrorType in Swift 2).

So in closure parameters list it expects Error as second parameter's type instead of NSError.

But inside of closure you need to type case error parameter to NSError if you want to use .domain/.code/etc.

Cannot assign value of type 'Void' (aka '()') to type '() - Void']

I found a way of conversion:

button.endPressAction = { self.didPressCell(indexPath) }

Cannot assign value type mismatch swift

Your error suggest type mismatch that means LLSimpleCamera! != LLSimpleCamera? .. there is no need to define type. .. you can use it something like

camera.onDeviceChange = { [weak self] (camera, device) -> Void in
print("Device changed.")
}


Related Topics



Leave a reply



Submit