internal protocol Reducer {
associatedtype S : BaseState
associatedtype A : BaseAction
func reduce(state: S, action: A) -> S
}
internal class ReducerImpl : Reducer {
func reduce(state: MainState, action: MainAction) -> MainState { //<-- Error because MainAction is a protocol not a concrete one.
return state
}
}
internal class MainState : BaseState {}
internal protocol MainAction : BaseAction {}
internal protocol BaseState {}
internal protocol BaseAction {}
If I change MainAction from protocol to class, the compile error disappears.
I've searching many articles to understand of this error but failed.
Do I have to pass a concrete parameter(eg. enum, class, struct) in reduce(...) function?
I want to make ReducerImpl can take various action type that conform MainAction.
Is there anyone who can give me explain about that error and why the Swift adopt this kind of rule.
actionparameter. I know you've simplified things for the question, but there comes a point when you've removed the point of the question. It is impossible to use this protocol for a useful purpose, which suggests you've removed the part that will provide the answer. - Rob NapierBaseStateandBaseState? I assume the reducers can operate on a variety of data types, thus constraining all of them to a common protocol for consuming it in the reducer doesn't seem feasible. Drop the twoBaseprotocols, they cause more problem than they solve. - Cristik