If it were up to me, I'd overhaul enums completely. The model I want is this:
enum MyEnum {
case
foo(label:String, Int),
bar(Double),
baz
}
Usage
let
a: MyEnum = .bar(123.0),
cpy: MyEnum = a, // .bar(123.0) case and its payload
val: Double = a() // 123.0 payload only
let
b: MyEnum = .bar(123.0),
c: MyEnum = .bar(456.0),
d: MyEnum = .baz
a == b // true (both are 'bar')
a === b // true (both 'bar' and same payload)
a == c // true
a === c // false (different payload)
a == b // false
a === b // false
I have essentially been using this model (via structs), and it works well. The trouble with using a struct is that the declaration of the struct involves a lot of code repetition (you have to declare both a static var and a static function overloaded with the same name for every 'case') and wasted storage for the backing id. Also, if it were built-in, Swift could warn you, when you, for example, try to compare two cases with payloads of different types.