<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="">I agree this would be useful. At the moment I have to hack around it with things like `var isFoo: Bool { if case .foo = self …`* with cases I commonly need, but this is definitely a feature that has come up before and I support. It is potentially related to getting the values through an accessor, which has also come up several times.<div class=""><br class=""></div><div class="">Sidenote, your `switch` example is actually trivial with existing syntax:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135); background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">switch</span><span style="color: #000000" class=""> </span>enumeration<span style="color: #000000" class=""> {</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">case</span><span style="color: #000000" class=""> .</span><span style="color: #31595d" class="">a</span><span style="color: #000000" class="">(.</span><span style="color: #31595d" class="">c</span><span style="color: #000000" class="">(</span><span style="color: #ba2da2" class="">let</span><span style="color: #000000" class=""> param)): </span>// or just .a(.c) if you don't need the value</div><div style="margin: 0px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""> <span style="color: #3e1e81" class="">print</span>(param)</div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(186, 45, 162); background-color: rgb(255, 255, 255);" class="">default<span style="color: #000000" class="">:</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(186, 45, 162); background-color: rgb(255, 255, 255);" class=""><span style="color: #000000" class=""> </span>break</div><div style="margin: 0px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">}</div><div class=""><br class=""></div><div class="">I use this from time to time switching over, e.g., optional enums.</div><div class=""><br class=""></div><div class="">*: ugliest syntax ever, and it can't even be used as a standalone expression.</div><div class=""><br class=""><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 20, 2017, at 8:44 AM, Ethan Diamond via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hello everyone,<div class=""><br class=""></div><div class="">One major pain point I've run into with Swift is the inability to evaluate the case of an enum that has associated values in a way that just returns a bool. We've been given the ability in a switch statement:</div><div class=""><br class=""></div><div class="">enum Enum {</div><div class=""> case a(param: String)</div><div class=""> case b(param: String)</div><div class="">}</div><div class=""><br class=""></div><div class="">let enumeration: Enum = a(param: "Hi")</div><div class="">switch enumeration {</div><div class=""> case a:</div><div class=""> // Do something</div><div class=""> case b:</div><div class=""> // Do something</div><div class="">}</div><div class=""><br class=""></div><div class="">We'e been given the ability in the context of an if statement:</div><div class=""><br class=""></div><div class=""><div class="">enum Enum {</div><div class=""> case a(param: String)</div><div class=""> case b(param: String)</div><div class="">}</div></div><div class=""><br class=""></div><div class="">let enumeration: Enum = a(param: "Hi")<br class=""></div><div class=""><br class=""></div><div class="">if case .a = enumeration { </div><div class=""> // Do something</div><div class="">}</div><div class=""><br class=""></div><div class="">But without a basic was of getting a bool for if an enum is a given case, here's a list of things I can't do:</div><div class=""><br class=""></div><div class=""><b class="">Where statements:</b></div><div class=""><br class=""></div><div class=""><div class="">enum Enum {</div><div class=""> case a(param: Enum2)</div><div class=""> case b(param: Enum2)</div><div class="">}</div></div><div class=""><br class=""></div><div class="">enum Enum2 {</div><div class=""> case c(param: String)</div><div class=""> case d(param: String)<br class=""></div><div class="">}</div><div class=""><br class=""></div><div class="">let enumeration: Enum = a(param: "Hi")</div><div class="">switch enumeration {</div><div class=""> case a(let inner) where [INNER CASE IS .c]</div><div class="">}</div><div class=""><br class=""></div><div class="">---------<br class=""></div><div class=""><br class=""></div><div class=""><b class="">Filter an array for a certain case:</b></div><div class=""><br class=""></div><div class="">Expertly explained by Erica Sadun here: <a href="http://ericasadun.com/2017/01/31/challenge-filtering-associated-value-enumeration-arrays/" class="">http://ericasadun.com/2017/01/31/challenge-filtering-associated-value-enumeration-arrays/</a></div><div class=""><br class=""></div><div class="">---------<br class=""></div><div class=""><br class=""></div><div class=""><b class="">Nicely set a UIButton to hidden if an enum is a certain case:</b></div><div class=""><b class=""><br class=""></b></div><div class="">enum State {</div><div class=""> case `default`</div><div class=""> case searching(results: [Result])</div><div class="">}</div><div class=""><br class=""></div><div class="">myButton.isHidden = [STATE IS .searching]</div><div class=""><br class=""></div><div class="">---------</div><div class=""><br class=""></div><div class="">I've run into this issue a ton of times because I tend to represent my views a State enums. I haven't seen anything on the board for plans for solving this issue, thought. Has there been any discussion about addressing it? Ideally I'd be able to do this:</div><div class=""><br class=""></div><div class=""><div class="">enum Enum {</div><div class=""> case a(param: String)</div><div class=""> case b(param: String)</div><div class="">}</div></div><div class=""><br class=""></div><div class="">let enumeration: Enum = a(param: "Hi")<br class=""></div><div class=""><br class=""></div><div class="">case .a = enumeration // Bool</div><div class="">case .a(let param) = enumeration // Bool, assigns "Hi" to "param"</div><div class=""><br class=""></div><div class="">Thanks!</div><div class="">Ethan</div><div class=""><br class=""></div></div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></div></div></body></html>