[swift-evolution] [Idea] Find alternatives to `switch self`
Kevin Lundberg
kevin at klundberg.com
Wed Mar 23 22:23:11 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]
}
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
> 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/20160323/3845e220/attachment.html>
More information about the swift-evolution
mailing list