I'd like to share some enum properties. Something like:
enum State {
case started
case succeeded
case failed
}
enum ActionState {
include State // what could that be?
case cancelled
}
class Action {
var state: ActionState = .started
func set(state: State) {
self.state = state
}
func cancel() {
self.state = .cancelled
}
}
I see why ActionState
can not inherit from State
(because the state cancelled
has no representation in State
) but I want to still be able to say "ActionState is like State with more options, and ActionState can get inputs that are of type State, because they are also of type ActionState"
I see how I could get the above logic to work with copying the cases in ActionState
and having a switch in the set
function. But I'm looking for a better way.
I know enum can't inherit in Swift, and I've read the protocol answer of swift-enum-inheritance. It doesn't address the need for "inheriting" or including cases from another enum, but only properties and variables.