Would it be possible in Swift to write a function that takes an enum and an enum case and compare them?
Below is the example use case, how would you write isSameAction function?
protocol Action {}
enum CounterAction: Action {
case IncrementBy(Int)
case DecrementBy(Int)
}
enum LoadingAction: Action {
case Loading, Loaded
}
let action1 = CounterAction.IncrementBy(1)
let action2 = CounterAction.DecrementBy(2)
let action3 = LoadingAction.Loaded
let actions: [Action] = [action1, action2, action3]
actions.filter(action in isSameAction(action, CounterAction.IncrementBy))
Actionprotocol, what exactly is it supposed to do? Sure it lets you put instances of bothCounterActionandLoadingActioninto the same array, but you can't actually do much with that. It has no requirements of its conforming types, so similar toAny, the only thing you can really do with objects that conform to that protocol is to cast them to their concrete type, and use them like that.