cfisher cfisher - 3 months ago 11
Swift Question

Adding a case to an existing enum with a protocol

I want to create a

protocol
that enforces a certain case on all
enums
conforming to this
protocol
.

For example, if I have a
enum
like this:

enum Foo{
case bar(baz: String)
case baz(bar: String)
}


I want to extend it with a
protocol
that adds another case:

case Fuzz(Int)


Is this possible?

Answer

no, since you can't declare a case outside of an enum.