[swift-evolution] [Idea] Find alternatives to `switch self`
Brent Royal-Gordon
brent at architechies.com
Thu Mar 24 06:26:24 CDT 2016
> This can be done today with no syntax changes (you'd have to return optional or handle the nil case though):
>
> var description: String? {
> return [
> .Hearts: "♥️",
> .Spades: "♠️",
> .Diamonds: "♦️",
> .Clubs: "♣️"
> ][self]
> }
"You have to handle the nil case" is a symptom of the real problem with this approach: you lose exhaustiveness checking.
--
Brent Royal-Gordon
Architechies
More information about the swift-evolution
mailing list