[swift-evolution] [Idea] Find alternatives to `switch self`

Tino Heth 2th at gmx.de
Wed Mar 23 06:03:52 CDT 2016


I encountered the same issues and agree that it can be tedious to deal with enums.
Imho the first variant (skipping the switch(self) {} doesn't offer enough benefit to justify a special case.

The second is nice because it keeps the "properties" of each case together — but afaics, Swift doesn't use the model of case classes (like http://docs.scala-lang.org/tutorials/tour/case-classes.html) for its enums, so it is no good fit for the language (btw, shouldn't the cases be lower case?).

As "isRed" is declared as "var", I would expect it can be changed, but it's redeclared "let" afterwards… maybe this could be simplified by using each case-block like an init-method:
   enum Suit: Int {
       let isRed: Bool

       case Hearts {
          isRed = true
       }
….

Tino


More information about the swift-evolution mailing list