I have an enum that implements a protocol:
protocol MyProtocol {
func myFunction()
}
enum MyEnum: MyProtocol {
case caseOne
case caseTwo
case caseThree
}
This protocol has only one method that can be implemented by default for all the enum's cases:
extension MyProtocol where Self == MyEnum {
func myFunction() {
// Default implementation.
}
}
But I would like to create a default implementation for each case of the enum, something like this (PSEUDOCODE):
extension MyProtocol where Self == MyEnum & Case == caseOne {
func myFunction() {
// Implementation for caseOne.
}
}
extension MyProtocol where Self == MyEnum & Case == caseTwo {
func myFunction() {
// Implementation for caseTwo.
}
}
extension MyProtocol where Self == MyEnum & Case == caseThree {
func myFunction() {
// Implementation for caseThree.
}
}
Is it possible?