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

Andrey Tarantsov andrey at tarantsov.com
Wed Mar 23 16:07:04 CDT 2016


Honestly, we really need this for a lot of different cases:

> * Allow you to attach member definitions to particular cases. It would be an error if they didn't all define the same members, unless there was a top-level catchall.
> 
>    enum Suit: Int {
>        var isRed: Bool { return false }
> 
>        case Hearts {
>            let description: String { return "♥️" }
>            let isRed: Bool { return true }
>        }
>        case Spades {
>            let description: String { return  "♠️" }
>        }
>        case Diamonds {
>            let description: String { return  "♦️" }
>            let isRed: Bool { return true }
>        }
>        case Clubs {
>            let description: String { return  "♣️" }
>        }
> 
>        static var all = [ Hearts, Spades, Diamonds, Clubs ]
>    }

A.



More information about the swift-evolution mailing list