[swift-evolution] Request: Ability to refer to an enum case in abstract (without its associated value)

Al Skipp al_skipp at fastmail.fm
Thu Dec 10 17:30:48 CST 2015

Maybe I’m misunderstanding your use case, but I believe what you require is already possible. When switching through enum cases, there’s no obligation to bind to the associated values if they’re not needed.

enum Foo {
  case Bar(String)
  case Baz(Int, Int)

let baz = Foo.Baz(1, 2)

switch baz {
case .Bar: print("Bar")
case .Baz: print("Baz")


> On 10 Dec 2015, at 22:05, Evan Maloney via swift-evolution <swift-evolution at swift.org> wrote:
> When an enum case takes one or more associated values, it acts more like a type than a value because it specifies a format for storing information without specifying the exact informations stored. We're able to refer to other types as such in Swift, but not in this case.
> I think it would be helpful if any enum with at least one case had a parallel representation containing the same cases but without associated values. It might look like:
> enum Foo
> {
>     case Bar(String)
>     case Baz(Int, Int)
>     // generated by the compiler; returns the parallel FooType
>     // with cases that don't have associated values
>     var enumType: FooType
> }
> // generated by the compiler when an enum
> // has at least one associated value
> enum FooType
> {
>     case Bar
>     case Baz
> }
> This would make it possible to be able to refer to cases in the abstract.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151210/3dfefda3/attachment.html>

More information about the swift-evolution mailing list