<div dir="ltr">I was about to provide this, but Krzysztof&#39;s example is more compact than mine:<div><br></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">enum</span><span style=""> Coin {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style=""><span class="" style="white-space:pre">        </span></span><span style="color:rgb(187,44,162)">case</span><span style=""> heads</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style=""><span class="" style="white-space:pre">        </span></span><span style="color:rgb(187,44,162)">case</span><span style=""> tails</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="">}</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">var</span><span style=""> result: </span><span style="color:rgb(79,129,135)">Coin</span><span style="">?</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style=""></span><br></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)"><span style="">switch</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(79,129,135)">result</span><span style="color:rgb(0,0,0)"> {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">case</span><span style=""> .</span><span style="color:rgb(61,29,129)">Some</span><span style="">(.</span><span style="color:rgb(49,89,93)">heads</span><span style="">): </span><span style="color:rgb(61,29,129)">print</span><span style="">(</span><span style="color:rgb(209,47,27)">&quot;heads&quot;</span><span style="">)</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">case</span><span style=""> .</span><span style="color:rgb(61,29,129)">Some</span><span style="">(.</span><span style="color:rgb(49,89,93)">tails</span><span style="">): </span><span style="color:rgb(61,29,129)">print</span><span style="">(</span><span style="color:rgb(209,47,27)">&quot;tails&quot;</span><span style="">)</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(209,47,27)"><span style="color:rgb(187,44,162)">case</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(61,29,129)">nil</span><span style="color:rgb(0,0,0)">: </span><span style="color:rgb(61,29,129)">print</span><span style="color:rgb(0,0,0)">(</span><span style="">&quot;not yet flipped&quot;</span><span style="color:rgb(0,0,0)">) </span><span style="color:rgb(0,132,0)">// exhaustive</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="">}</span></p></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, May 5, 2016 at 4:52 PM, Krzysztof Siejkowski via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto">It doesn’t compile because you’re switching on the Optional and trying to pattern match it to Coin.</div><div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto"><br></div><div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto">It compiles right when you pattern match it to Optional&lt;Coin&gt;:</div><div style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto"><br></div><div style="font-family:Helvetica,Arial;font-size:13px;margin:0px"><p style="margin:0px;font-size:14px;line-height:normal;font-family:Monaco"><span>switch</span><span> </span><span>result</span><span> {</span></p>
<p style="margin:0px;font-size:14px;line-height:normal;font-family:Monaco"><span>case</span><span> .</span><span>heads</span><span>?: </span><span>print</span><span>(</span><span>&quot;heads&quot;</span><span>)</span></p>
<p style="margin:0px;font-size:14px;line-height:normal;font-family:Monaco"><span>case</span><span> .</span><span>tails</span><span>?: </span><span>print</span><span>(</span><span>&quot;tails&quot;</span><span>)</span></p><span class="">
<p style="margin:0px;font-size:14px;line-height:normal;font-family:Monaco"><span>case</span><span> </span><span>nil</span><span>: </span><span>print</span><span>(</span><span>&quot;not yet flipped&quot;</span><span>)</span></p>
<p style="margin:0px;font-size:14px;line-height:normal;font-family:Monaco"><span>}</span></p></span></div><div><br></div>Best,<div>Krzysztof<div><div class="h5"><br> <div></div> <br><p>On 5 May 2016 at 17:42:24, Eric Miller via swift-evolution (<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>) wrote:</p> </div></div><blockquote type="cite"><span><div><div></div><div><div><div class="h5">






<div dir="ltr">Wondering if you guys think this is a reasonable
idea.
<div><br></div>
<div>I was switching on an optional enum today, and naturally
gravitated towards including nil as a case:</div>
<div><br></div>
<div>enum Coin {</div>
<div>  case heads</div>
<div>  case tails</div>
<div>}</div>
<div>var result: Coin?</div>
<div><br></div>
<div>switch result {</div>
<div>case heads: print(&quot;heads&quot;)</div>
<div>case tails: print(&quot;tails&quot;)</div>
<div>case nil: print(&quot;not yet flipped&quot;) // exhaustive</div>
<div>}</div>
<div><br></div>
<div>Doesn&#39;t compile, and of course I can if-let or guard to unwrap
instead, but I like the compactness of this.</div>
</div></div></div>


_______________________________________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></div></span></blockquote></div></div><br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div>