<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 10, 2015, at 5:23 PM, Joe Groff via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" class=""><div class=""><br class="Apple-interchange-newline">On Dec 10, 2015, at 5:19 PM, J. Cheyo Jimenez &lt;<a href="mailto:cheyo@masters3d.com" class="">cheyo@masters3d.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class=""><span class="" style="color: rgb(255, 255, 255); font-family: Inconsolata, Monaco, Menlo, 'Ubuntu Mono', Consolas, source-code-pro, monospace; font-size: 12px; white-space: pre-wrap; background-color: rgb(27, 47, 67);">//Swift version 2.2-dev</span><span class="" style="color: rgb(255, 255, 255); font-family: Inconsolata, Monaco, Menlo, 'Ubuntu Mono', Consolas, source-code-pro, monospace; font-size: 12px; white-space: pre-wrap; background-color: rgb(27, 47, 67);"><br class=""></span></div><span class="" style="color: rgb(255, 255, 255); font-family: Inconsolata, Monaco, Menlo, 'Ubuntu Mono', Consolas, source-code-pro, monospace; font-size: 12px; white-space: pre-wrap; background-color: rgb(27, 47, 67);">enum case 'CaseWithPayload' not found</span></div></div></blockquote><div class=""><br class=""></div><div class="">Sorry, '.CaseWithPayload' was intended as a stand-in for whatever your specific case with payload is named:</div><div class=""><br class=""></div><div class="">enum Foo {</div><div class="">&nbsp; case A(Int)</div><div class="">&nbsp; case B</div><div class="">}</div><div class=""><br class=""></div><div class="">let foo = Foo.A(0)</div><div class=""><br class=""></div><div class="">switch foo {</div><div class="">case .A: print("hi")</div><div class="">case .B: print("bye")</div><div class="">}</div><div class=""><br class=""></div><div class="">-Joe</div></div></div></blockquote><div><br class=""></div>This discussion and the ‘List of all enum values’ thread makes me think of a related feature that most people probably aren’t aware of — referring to an enum case constructor for a case with a payload, without actually applying it, yields a function value that you can pass around, eg in the above code ‘Foo.A’ has type Int -&gt; Foo.</div><div><br class=""></div><div>In the past we’ve also talked about adding ‘projections’ which test for that enum case and wrap the payload in an optional, where Foo.A would have two overloads, the constructor Int -&gt; Foo and a projection Foo -&gt; Int?.</div><div><br class=""></div><div>It might be useful for enum cases to witness protocol requirements, too — has anyone wanted this?</div><div><br class=""></div><div>Just food for thought,</div><div><br class=""></div><div>Slava</div><div><br class=""><blockquote type="cite" class=""><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class=""><div class=""><span class="" style="color: rgb(255, 255, 255); font-family: Inconsolata, Monaco, Menlo, 'Ubuntu Mono', Consolas, source-code-pro, monospace; font-size: 12px; white-space: pre-wrap; background-color: rgb(27, 47, 67);"><br class=""></span></div><div class=""><span class="" style="color: rgb(255, 255, 255); font-family: Inconsolata, Monaco, Menlo, 'Ubuntu Mono', Consolas, source-code-pro, monospace; font-size: 12px; white-space: pre-wrap; background-color: rgb(27, 47, 67);"><br class=""></span></div></div></div><div class="gmail_extra" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""><div class="gmail_quote">On Thu, Dec 10, 2015 at 3:31 PM, Joe Groff via swift-evolution<span class="Apple-converted-space">&nbsp;</span><span dir="ltr" class="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</span><span class="Apple-converted-space">&nbsp;</span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div class="" style="word-wrap: break-word;"><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 10, 2015, at 2:05 PM, Evan Maloney via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class=""><div class=""><div class="" style="word-wrap: break-word;"><div class="">I'm not sure if this is what you're driving at, but I've found a use-case for the ability to refer to an enum case generically without reference to any of its associated values.</div><div class=""><br class=""></div><div class="">Let me give you an example:</div><div class=""><br class=""></div><div class="">In our app, we have an enum that represents all the different<span class="Apple-converted-space">&nbsp;</span><i class="">screens</i>&nbsp;to which the user can navigate. (A<span class="Apple-converted-space">&nbsp;</span><i class="">screen</i>&nbsp;in our case usually means a view controller or hierarchy thereof.)</div><div class=""><br class=""></div><div class="">Because each screen might require specific view model object(s) to render their content, some of our enum cases have associated values to store the required view model objects.</div><div class=""><br class=""></div><div class="">This allows an enum value to contain all the information needed to present any screen to the user, fully populated with content.</div><div class=""><br class=""></div><div class="">However, in a few instances I've found it would be helpful to be able to refer to a screen in the abstract and be able to 'switch' against it without any associated values. (This would allow me to be able to refer to, say, "the User Account screen" in the abstract, whereas now I can only refer to "the User Account screen displaying details for this particular user".)</div></div></div></blockquote><div class=""><br class=""></div><div class="">I might be missing something, but you can do this already. 'case .CaseWithPayload:' matches any CaseWithPayload regardless of its payload.</div><div class=""><br class=""></div><div class="">-Joe</div><br class=""><blockquote type="cite" class=""><div class=""><div class="" style="word-wrap: break-word;"><div class="">We've identified two possible solutions to this issue and have implemented one of them, but it is still sub-optimal:</div><div class=""><br class=""></div><div class="">• One option involves maintaining a parallel enum with the same case names but without any associated values. These parallel structures need to be manually maintained, which is something the compiler cannot enforce.</div><div class=""><br class=""></div><div class="">• Another option involves removing the associated values from the enum and passing around objects to contain the necessary view model objects. At various points, we assert that the view model container object is of the expected type for the enum case, but again, that now moves to runtime an error that otherwise would've been caught by the compiler.</div><div class=""><br class=""></div><div class="">---</div><div class=""><br class=""></div><div class="">When an enum case takes one or more associated values, it acts more like a<span class="Apple-converted-space">&nbsp;</span><i class="">type</i>&nbsp;than a<span class="Apple-converted-space">&nbsp;</span><i class="">value</i>&nbsp;because it specifies a format for storing information without specifying the exact informations stored. We're able to refer to other types as such in Swift, but not in this case.</div><div class=""><br class=""></div><div class="">I think it would be helpful if any enum with at least one case had a parallel representation containing the same cases but without associated values. It might look like:</div><div class=""><br class=""></div><div class="">enum Foo<br class="">{<br class="">&nbsp; &nbsp;&nbsp;case Bar(String)<br class="">&nbsp; &nbsp;&nbsp;case Baz(Int, Int)<br class=""><br class="">&nbsp; &nbsp;&nbsp;// generated by the compiler; returns the parallel FooType<br class="">&nbsp; &nbsp;&nbsp;// with cases that don't have associated values<br class="">&nbsp; &nbsp;&nbsp;var enumType: FooType<br class="">}<br class=""><br class="">// generated by the compiler when an enum</div><div class="">// has at least one associated value<br class="">enum FooType<br class="">{<br class="">&nbsp; &nbsp;&nbsp;case Bar<br class="">&nbsp; &nbsp;&nbsp;case Baz<br class="">}<br class=""></div><div class=""><br class=""></div><div class="">This would make it possible to be able to refer to cases in the abstract.</div><div class=""><br class=""></div><div class="">Perhaps there's a totally different solution to this class of problem, but that's what I came up with. Would love to hear your thoughts.</div><div class=""><br class=""></div><div class="">E.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><blockquote type="cite" class="">On Dec 10, 2015, at 8:24 AM, plx via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class="">FWIW, as long as we’re asking for some compiler assistance generating useful enumeration-related boilerplate, I’d like to request that something along these lines be possible in some version of Swift:<br class=""><br class="">@synthesize_case_enum<br class="">enum Example {<br class=""><br class="">&nbsp;case Foo(X)<br class="">&nbsp;case Bar<br class="">&nbsp;case Baz(Y)<br class=""><br class="">}<br class=""><br class="">…which would then by default expand to something like this:<br class=""><br class="">enum ExampleCase : Int {<br class=""><br class="">&nbsp;case Foo<br class="">&nbsp;case Bar<br class="">&nbsp;case Baz<br class=""><br class="">}<br class=""><br class="">extension Example {<br class=""><br class="">&nbsp;var enumerationCase: ExampleCase {<br class="">&nbsp;&nbsp;&nbsp;get {<br class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;switch self {<br class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case .Foo(_): return .Foo<br class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case .Bar(_): return .Bar<br class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case .Baz(_): return .Baz<br class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br class="">&nbsp;&nbsp;&nbsp;}<br class="">&nbsp;} &nbsp;<br class=""><br class="">}<br class=""><br class=""></blockquote></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=RoDF4MveSEMYBIqIJA6ub1g8cOZ-2BVYvqV-2FqygPhjPn-2BczUm64ISF8-2FlK1enkxDQz6q7GSWrsdAoKGnpWF-2FlIt40kwzHOWVN2dUe3K0WeiyeTONaz9-2Bbf4V4mgbH-2F4B8bTxNXQ7RCAGapITaK9Oq7ncuR45NrYV-2BH-2BXBIitf0eLrLSXCmXz-2BctgN-2Bb-2FjvsLh26L1VFDnWdPyXHESsT5yApy6q8JffaNKSlUPNfzNQ2To-3D" alt="" width="1" height="1" border="0" class="" style="min-height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;"></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=OWK4tSasaK2n-2FQIIcS9Ug-2FuFXG-2BJ3z6cFMLgm306hDcRnZx8MEHgUdBD9OPoyQy1YEHDhhEReoz7KLXM2XFB-2FDDCMAZ7g2Y7Y-2FdwiMHDNOTpydqGRY-2FFWiZlqVhiqv543-2FNoT9o55KEglPg3Ipaduzl06NNF-2BH33lx8IZYRkSlouIqjjQM7IHd-2BZ9dp-2FS3250HXPf5XUQJpR0aSt4KjKqAEGtVExV4k-2BPq51dSIvCak-3D" alt="" width="1" height="1" border="0" class="" style="min-height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;"></div><br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></blockquote></div></div></div></blockquote></div><br class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=NLTid1W7V2mxBEfr5Y3KfTntaxSmOQp5vjACZc9Eh19-2BSf1wLd1HqXfHdH-2FogPcE0xlwSVTp25Pk2lijrb4zG4C0EvfZrtuxWNK7o-2FN0grAQ0Akqr144Bjmd4ZbF3puvJycDrzRuT2CD8-2FruNaY25JrcGFtrEVYF3FmFAvp9hgqU0wqqgTpUThwji2loKkO4gSxing-2BdySpIvcp3-2BMZmgR5Rr01ir3IB4heJF6Pk4bU-3D" alt="" width="1" height="1" border="0" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class=""><span class="Apple-converted-space">&nbsp;</span></span><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">_______________________________________________</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">swift-evolution mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:swift-evolution@swift.org" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">swift-evolution@swift.org</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br class=""></body></html>