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
"File Not Found", "Linker Command Failed with Exit Code 1" in Xcode 4.5.1
Scale Text Label by Screen Size
Present a View Controller, Dismiss It and Present a Different One in Swift
iOS 7.1 Uitableviewcell Content Overlaps with Ones Below
Reconnecting to Disconnected Peers
How to Only Show Bottom Border of Uitextfield in Swift
Uicollectionview Cell Spacing Based on Device Screen Size
Show Datepicker on Textfield Tap
Mfmessagecomposeviewcontroller iOS7 Addattachmentdata:Typeidentifier:Filename: Not Working
(Null) Libc++Abi.Dylib: Terminate Called Throwing an Exception
How to Show Complete List When Keyboard Is Showing Up in Swiftui
How to Show Uipickerview When Selecting Uitextfield
Tableview Rounded Corners and Shadow
Core Bluetooth - Constant Rssi Updates of In-Range Devices
iOS - Return to Safari from Native App Without Opening New Tab