I have a class StateMachine<A>
final class StateMachine<A> {
private var previousState: State? = nil
private var currentState: State
private var content: A?
var delegate: StateMachineDelegate?
var state: State = .loading {
didSet {
previousState = currentState
currentState = state
}
}
init(currentState: State, delegate: StateMachineDelegate?) {
self.currentState = currentState
}
}
and a delegate protocol StateMachineDelegate
protocol StateMachineDelegate {
func updateWith(content: A)
}
I'm trying to express that if the StateMachine is created with type A, the delegate should implement the method func updateWith(content: A) which accepts a parameter of the same type A. Is this possible?
enum State); you must initialize all non-optional properties in yourinit; you must specifyassociatedtypein your delegate protocol.