[swift-evolution] [Pitch] Numeric enum cases

Saagar Jha saagar at saagarjha.com
Tue Nov 22 18:34:47 CST 2016


I'm curious about the use case for this. For tuples it's a positional
argument; how does this apply to enum cases which shouldn't depend on their
order?
On Tue, Nov 22, 2016 at 05:43 Adrian Zubarev via swift-evolution <
swift-evolution at swift.org> wrote:

> Have we already discussed this somewhere?
>
> enum MyEnum {
>     case 0
>     case 1(String)
> }
>
> // or
>
> enum MyEnum {
>     case `0`
>     case `1`(String)
> }
>
> let zero: MyEnum = .0
> let one = MyEnum.1("Swift")
>
> switch zero {
>
> case .0:
>    print("zero")
>
> case .1(let string)
>    print(string)
> }
>
>
> Tuples have this .# syntax, where the number is the index of the tuple
> value. Can’t we allow this on enum cases as well?
> ------------------------------
>
> This is additive and something for phase 2, but I’d like to know if we
> want to allow this?! :)
>
>
>
> --
> Adrian Zubarev
> Sent with Airmail
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161123/d56a1e58/attachment.html>


More information about the swift-evolution mailing list