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]
  }


On 3/23/2016 8:42 PM, Patrick Smith via swift-evolution wrote:
> Maybe the dictionary literal syntax could be used as a shorthand?
>
> enum Suit: Int {
>   case Hearts, Spades, Diamonds, Clubs
>
>   var description: String {
>     return switch self [
>       .Hearts: "♥️",
>       .Spades: "♠️",
>       .Diamonds: "♦️",
>       .Clubs: "♣️"
>     ]
>   }
>
>   var isRed: Bool {
>     return switch self [
>       .Hearts: true,
>       .Diamonds: true,
>       .Spades: false,
>       .Clubs: false
>     ]
>   }
> }
>
>
> Patrick
>
>
> _______________________________________________
> swift-evolution mailing list
> [email protected]
> https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to