<div dir="ltr"><div>Here's proposal link:</div><a href="https://github.com/rintaro/swift-evolution/blob/conditional-switch-case/proposals/NNNN-conditional-switch-case.md">https://github.com/rintaro/swift-evolution/blob/conditional-switch-case/proposals/NNNN-conditional-switch-case.md</a><br><div><br></div><div>Fixed some typos, including my name :)</div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-05-10 17:32 GMT+09:00 rintaro ishizaki <span dir="ltr"><<a href="mailto:fs.output@gmail.com" target="_blank">fs.output@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi evolution community,<div><br></div><div>This proposal allows you to enclose switch cases with #if directive.<br></div><div>Implementation: <a href="https://github.com/apple/swift/pull/9457" target="_blank">https://github.com/apple/<wbr>swift/pull/9457</a></div><div>This is one of the oldest SR issue:</div><div><a href="https://bugs.swift.org/browse/SR-2" target="_blank">https://bugs.swift.org/browse/<wbr>SR-2</a></div><div><a href="https://bugs.swift.org/browse/SR-4196" target="_blank">https://bugs.swift.org/browse/<wbr>SR-4196</a></div><div><br></div><div>Thanks!</div><div>Rintaro</div><div><br></div><div><br></div><div><h1 style="box-sizing:border-box;margin:0px 0px 16px;line-height:1.25;padding-bottom:0.3em;border-bottom:1px solid rgb(234,236,239);color:rgb(36,41,46);font-family:-apple-system,system-ui,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol"">Allow <code style="box-sizing:border-box;font-family:sfmono-regular,consolas,"liberation mono",menlo,courier,monospace;font-size:inherit;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">#if</code> to guard switch case clauses</h1><ul style="box-sizing:border-box;padding-left:2em;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px"><li style="box-sizing:border-box">Proposal: <a href="https://gist.github.com/rintaro/NNNN-filename.md" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration-line:none" target="_blank">SE-NNNN</a></li><li style="box-sizing:border-box;margin-top:0.25em">Authors: <a href="https://github.com/rintaro" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration-line:none" target="_blank">Rintaro Ishziaki</a></li><li style="box-sizing:border-box;margin-top:0.25em">Review Manager: TBD</li><li style="box-sizing:border-box;margin-top:0.25em">Status: <span style="box-sizing:border-box;font-weight:600">Awaiting review</span></li></ul><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom:1px solid rgb(234,236,239);color:rgb(36,41,46);font-family:-apple-system,system-ui,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol""><a id="m_-5841035384072243354gmail-user-content-introduction" class="m_-5841035384072243354gmail-anchor" href="https://gist.github.com/rintaro/a5a9d9836027d7df7a5326a3a8cf9d89#introduction" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration-line:none;float:left;padding-right:4px;line-height:1" target="_blank"></a>Introduction</h2><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px">This proposal adds ability to guard switch <code style="box-sizing:border-box;font-family:sfmono-regular,consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">case</code> clauses with <code style="box-sizing:border-box;font-family:sfmono-regular,consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">#if</code> directives.</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px">Swift-evolution thread: <a href="https://lists.swift.org/pipermail/swift-evolution/" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration-line:none" target="_blank">Not yet</a></p><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom:1px solid rgb(234,236,239);color:rgb(36,41,46);font-family:-apple-system,system-ui,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol""><a id="m_-5841035384072243354gmail-user-content-motivation" class="m_-5841035384072243354gmail-anchor" href="https://gist.github.com/rintaro/a5a9d9836027d7df7a5326a3a8cf9d89#motivation" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration-line:none;float:left;padding-right:4px;line-height:1" target="_blank"></a>Motivation</h2><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px">When you want to switch cases only for certain compilation condition, say switching <code style="box-sizing:border-box;font-family:sfmono-regular,consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">#if os(Linux)</code> guarded enum cases, right now you have to write <code style="box-sizing:border-box;font-family:sfmono-regular,consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">switch</code> twice:</p><div class="m_-5841035384072243354gmail-highlight m_-5841035384072243354gmail-highlight-source-swift" style="box-sizing:border-box;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px"><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-radius:3px;word-break:normal"><span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">enum</span> <span class="m_-5841035384072243354gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">Operation</span> {
<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> <span class="m_-5841035384072243354gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">output</span>(<span class="m_-5841035384072243354gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">String</span>)
#<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> <span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">os</span>(<span class="m_-5841035384072243354gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">Linux</span>)
<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> <span class="m_-5841035384072243354gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">syscall</span>(Syscall)
#<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">endif</span>
}
<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">func</span> <span class="m_-5841035384072243354gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">execute</span>(<span class="m_-5841035384072243354gmail-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)"><span class="m_-5841035384072243354gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">operation</span></span>: Operation) {
#<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> !<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">os</span>(<span class="m_-5841035384072243354gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">Linux</span>)
<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">switch</span> operation {
<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> .<span class="m_-5841035384072243354gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">output</span>(<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> str)<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">:</span>
<span class="m_-5841035384072243354gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">print</span>(str)
}
#<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">else</span>
<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">switch</span> operation {
<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> .<span class="m_-5841035384072243354gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">output</span>(<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> str)<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">:</span>
<span class="m_-5841035384072243354gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">print</span>(str)
<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> .<span class="m_-5841035384072243354gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">syscall</span>(<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> call)<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">:</span>
call.<span class="m_-5841035384072243354gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">execute</span>()
}
#<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">endif</span>
}</pre></div><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px">This is annoying and error prone.</p><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom:1px solid rgb(234,236,239);color:rgb(36,41,46);font-family:-apple-system,system-ui,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol""><a id="m_-5841035384072243354gmail-user-content-proposed-solution" class="m_-5841035384072243354gmail-anchor" href="https://gist.github.com/rintaro/a5a9d9836027d7df7a5326a3a8cf9d89#proposed-solution" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration-line:none;float:left;padding-right:4px;line-height:1" target="_blank"></a>Proposed solution</h2><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px">This proposal allows <code style="box-sizing:border-box;font-family:sfmono-regular,consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">#if</code> to guard switch case clauses.</p><div class="m_-5841035384072243354gmail-highlight m_-5841035384072243354gmail-highlight-source-swift" style="box-sizing:border-box;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px"><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-radius:3px;word-break:normal"><span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">func</span> <span class="m_-5841035384072243354gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">execute</span>(<span class="m_-5841035384072243354gmail-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)"><span class="m_-5841035384072243354gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">operation</span></span>: Operation) {
<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">switch</span> operation {
<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> .<span class="m_-5841035384072243354gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">output</span>(<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> str)<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">:</span>
<span class="m_-5841035384072243354gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">print</span>(str)
#<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> <span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">os</span>(<span class="m_-5841035384072243354gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">Linux</span>)
<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> .<span class="m_-5841035384072243354gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">syscall</span>(<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> call)<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">:</span>
call.<span class="m_-5841035384072243354gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">execute</span>()
#<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">endif</span>
}
}</pre></div><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom:1px solid rgb(234,236,239);color:rgb(36,41,46);font-family:-apple-system,system-ui,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol""><a id="m_-5841035384072243354gmail-user-content-detailed-design" class="m_-5841035384072243354gmail-anchor" href="https://gist.github.com/rintaro/a5a9d9836027d7df7a5326a3a8cf9d89#detailed-design" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration-line:none;float:left;padding-right:4px;line-height:1" target="_blank"></a>Detailed design</h2><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px">This change shouldn't affect existing <code style="box-sizing:border-box;font-family:sfmono-regular,consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">#if</code> directives <em style="box-sizing:border-box">within</em><wbr> <code style="box-sizing:border-box;font-family:sfmono-regular,consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">case</code> clauses. This code should works as expected:</p><div class="m_-5841035384072243354gmail-highlight m_-5841035384072243354gmail-highlight-source-swift" style="box-sizing:border-box;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px"><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-radius:3px;word-break:normal"><span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">func</span> <span class="m_-5841035384072243354gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">foo</span>(<span class="m_-5841035384072243354gmail-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)"><span class="m_-5841035384072243354gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">x</span></span>: MyEnum) {
<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">switch</span> x {
<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> .<span class="m_-5841035384072243354gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">some</span>(<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> str)<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">:</span>
<span class="m_-5841035384072243354gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">doSomething</span>(str)
#<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> PRINT_SOME
<span class="m_-5841035384072243354gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">print</span>(str)
#<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">endif</span>
<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> .<span class="m_-5841035384072243354gmail-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)">other</span><span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">:</span>
<span class="m_-5841035384072243354gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">doOther</span>()
}
}</pre></div><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px">Only if the next token after <code style="box-sizing:border-box;font-family:sfmono-regular,consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">#if</code> is <code style="box-sizing:border-box;font-family:sfmono-regular,consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">case</code> or <code style="box-sizing:border-box;font-family:sfmono-regular,consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">default</code>, the Parser treat it as guarding <code style="box-sizing:border-box;font-family:sfmono-regular,consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.05);border-radius:3px">case</code> clauses.</p><div class="m_-5841035384072243354gmail-highlight m_-5841035384072243354gmail-highlight-source-swift" style="box-sizing:border-box;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px"><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-radius:3px;word-break:normal"><span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">func</span> <span class="m_-5841035384072243354gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">foo</span>(<span class="m_-5841035384072243354gmail-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)"><span class="m_-5841035384072243354gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">x</span></span>: MyEnum) {
<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">switch</span> x {
<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> .<span class="m_-5841035384072243354gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">some</span>(<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> str)<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">:</span>
<span class="m_-5841035384072243354gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">doSomething</span>(str)
#<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> HAS_OTHER
<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> .<span class="m_-5841035384072243354gmail-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)">other</span><span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">:</span>
<span class="m_-5841035384072243354gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">doOther</span>()
}
#<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">endif</span>
}</pre></div><div class="m_-5841035384072243354gmail-highlight m_-5841035384072243354gmail-highlight-source-swift" style="box-sizing:border-box;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px"><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-radius:3px;word-break:normal"><span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">func</span> <span class="m_-5841035384072243354gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">foo</span>(<span class="m_-5841035384072243354gmail-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)"><span class="m_-5841035384072243354gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">x</span></span>: MyEnum) {
<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">switch</span> x {
<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> .<span class="m_-5841035384072243354gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">some</span>(<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> str)<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">:</span>
<span class="m_-5841035384072243354gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">doSomething</span>(str)
#<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> HAS_OTHER
<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">default</span><span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">:</span>
<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">break</span>
#<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">endif</span>
}</pre></div><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px">Error cases:</p><div class="m_-5841035384072243354gmail-highlight m_-5841035384072243354gmail-highlight-source-swift" style="box-sizing:border-box;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px"><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-radius:3px;word-break:normal"> <span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">switch</span> x {
<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> .<span class="m_-5841035384072243354gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">some</span>(<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> str)<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">:</span>
<span class="m_-5841035384072243354gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">doSomething</span>(str)
#<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> HAS_OTHER
<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> .<span class="m_-5841035384072243354gmail-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)">other</span><span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">:</span>
<span class="m_-5841035384072243354gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">doOther</span>()
#<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">else</span>
<span class="m_-5841035384072243354gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">doMore</span>() <span class="m_-5841035384072243354gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_-5841035384072243354gmail-pl-c" style="box-sizing:border-box">//</span> error: all statements inside a switch must be covered by a 'case' or 'default'</span>
<span class="m_-5841035384072243354gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"></span>#<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">endif</span>
}</pre></div><div class="m_-5841035384072243354gmail-highlight m_-5841035384072243354gmail-highlight-source-swift" style="box-sizing:border-box;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px"><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-radius:3px;word-break:normal"> <span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">switch</span> x {
<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> .<span class="m_-5841035384072243354gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">some</span>(<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> str)<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">:</span>
<span class="m_-5841035384072243354gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">doSomething</span>(str)
#<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> HAS_OTHER
<span class="m_-5841035384072243354gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">doMore</span>()
<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> .<span class="m_-5841035384072243354gmail-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)">other</span><span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">:</span>
<span class="m_-5841035384072243354gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">doOther</span>() <span class="m_-5841035384072243354gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_-5841035384072243354gmail-pl-c" style="box-sizing:border-box">//</span> error: 'case' label can only appear inside a 'switch' statement</span>
<span class="m_-5841035384072243354gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"></span>#<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">else</span>
}</pre></div><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46)"><span style="font-family:-apple-system,system-ui,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px">You can guard multiple cases as long as it is guarding whole clauses</span><font face="-apple-system, system-ui, segoe ui, helvetica, arial, sans-serif, apple color emoji, segoe ui emoji, segoe ui symbol"><span style="font-size:16px">:</span></font></p><div class="m_-5841035384072243354gmail-highlight m_-5841035384072243354gmail-highlight-source-swift" style="box-sizing:border-box;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,system-ui,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:16px"><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,"liberation mono",menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-radius:3px;word-break:normal"> <span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">switch</span> x {
<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> .<span class="m_-5841035384072243354gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">some</span>(<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> str)<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">:</span>
<span class="m_-5841035384072243354gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">doSomething</span>(str)
#<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> HAS_OTHERS
<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> .<span class="m_-5841035384072243354gmail-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)">other</span><span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">:</span>
<span class="m_-5841035384072243354gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">doOther</span>()
<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> .<span class="m_-5841035384072243354gmail-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)">more</span><span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">:</span>
<span class="m_-5841035384072243354gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">doMore</span>()
#<span class="m_-5841035384072243354gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">else</span>
}</pre><div><br></div></div><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom:1px solid rgb(234,236,239);color:rgb(36,41,46);font-family:-apple-system,system-ui,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol""><a id="m_-5841035384072243354gmail-user-content-source-compatibility" class="m_-5841035384072243354gmail-anchor" href="https://gist.github.com/rintaro/a5a9d9836027d7df7a5326a3a8cf9d89#source-compatibility" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration-line:none;float:left;padding-right:4px;line-height:1" target="_blank"></a></h2></div></div>
</blockquote></div><br></div>