[swift-evolution] [Idea] Find alternatives to `switch self`
Charles Constant
charles at charlesism.com
Fri Apr 8 17:12:11 CDT 2016
Would this still be an issue if switch statements were less verbose? I
don't see why a "switch" statements should be so much more verbose than an
"if statement".
Writing boiler plate for switch statements is by far my #1 irritation at
the moment (now that argument labels have been made beautiful - thanks! -
and Generics are being improved).
As Paul alluded to, this has been discussed with
https://github.com/cacruden/swift-evolution/blob/master/proposals/0024-Pattern-Matching-Partial-Function.md
On Fri, Apr 8, 2016 at 2:30 PM, Charles Srstka via swift-evolution <
swift-evolution at swift.org> wrote:
> On Mar 23, 2016, at 5:13 AM, Brent Royal-Gordon via swift-evolution <
> swift-evolution at swift.org> wrote:
>
>
> * 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 ]
> }
>
>
> Oh my, I absolutely *love this.* This would be a godsend for making
> ErrorType enums that bridge nicely to NSErrors, with code and userInfo
> properties attached to each case.
>
> +1.
>
> Charles
>
>
> _______________________________________________
> 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/20160408/1b0450f9/attachment.html>
More information about the swift-evolution
mailing list