I've a little issue I cannot find an elegant way to use a closure with an associated type as a Void in a protocol.
Let's say I've the following protocol:
protocol MyProtocol {
associatedtype OutputDataType
associatedtype InputDataType
var isCompleted: ( (InputDataType) -> OutputDataType)? { get set }
}
Now I've a class that conforms to this protocol with Void type inside the closure like this:
class MyClass: MyProtocol {
var isCompleted: ( () -> Void )? // Error: Type 'MyClass' does not conform to protocol 'MyProtocol'
}
So I tried this:
var isCompleted: ( (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 '()'?
And ended up with this "weird" syntax:
var isCompleted: ( (()) -> Void )?
or this verbose one:
typealias InputDataType = Void
var isCompleted: ( (InputDataType) -> Void )?
But now when I want to assign this closure in an other class I need to explicitely use a "_" in parameter:
myClass.isCompleted = { _ in
// other code
}
Isn't possible to use something like this:
myClass.isCompleted = {
// other code
}
So do you know if it would be possible to get something more elegant like the example I quoted and expected?