<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi there,<div class=""><br class=""></div><div class=""><div class="">I was wondering if the community would like Swift to have a switch statement with optional binding.</div><div class=""><br class=""></div><div class="">Take this simple dictionary as an example:</div><div class=""><br class=""></div><div class=""><span class="" style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures; color: rgb(187, 40, 164);">let</span><span class="" style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;"> cityIDs = [</span><span class="" style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures; color: rgb(212, 45, 10);">"Paris"</span><span class="" style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;">: </span><span class="" style="line-height: normal; font-family: 'Fira Code'; font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);">1</span><span class="" style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;">, </span><span class="" style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures; color: rgb(212, 45, 10);">"London"</span><span class="" style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;">: </span><span class="" style="line-height: normal; font-family: 'Fira Code'; font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);">2</span><span class="" style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;">]</span></div><div class=""><br class=""></div><div class="">Currently, this is how things are done if <span class="" style="font-family: Menlo; font-size: 11px;">parisCityID</span> is used <span class="">only</span><i class=""> once</i> within an <span class="" style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures; color: rgb(187, 40, 164);">if</span><span class="" style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;">-</span><span class="" style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures; color: rgb(187, 40, 164);">let</span> statement for only a <span style="color: rgb(187, 40, 164); font-family: Menlo; font-size: 11px;" class="">switch</span> statement: </div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 40, 164);">if</span><span class="" style="font-variant-ligatures: no-common-ligatures;"> </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 40, 164);">let</span><span class="" style="font-variant-ligatures: no-common-ligatures;"> parisCityID = </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);">cityIDs</span><span class="" style="font-variant-ligatures: no-common-ligatures;">[</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(212, 45, 10);">"Paris"</span><span class="" style="font-variant-ligatures: no-common-ligatures;">] {</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"> </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 40, 164);">switch</span><span class="" style="font-variant-ligatures: no-common-ligatures;"> parisCityID {</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"> </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 40, 164);">case</span><span class="" style="font-variant-ligatures: no-common-ligatures;"> </span><span class="" style="font-size: 12px; line-height: normal; font-family: 'Fira Code'; font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);">0</span><span class="" style="font-variant-ligatures: no-common-ligatures;">..<</span><span class="" style="font-size: 12px; line-height: normal; font-family: 'Fira Code'; font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);">10</span><span class="" style="font-variant-ligatures: no-common-ligatures;">:</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"> </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(61, 29, 129);">print</span><span class="" style="font-variant-ligatures: no-common-ligatures;">(</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(212, 45, 10);">"Paris city ID: </span><span class="" style="font-variant-ligatures: no-common-ligatures;">\</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(212, 45, 10);">(</span><span class="" style="font-variant-ligatures: no-common-ligatures;">parisCityID</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(212, 45, 10);">)"</span><span class="" style="font-variant-ligatures: no-common-ligatures;">)</span></div><div class="" style="margin: 0px; line-height: normal; color: rgb(187, 40, 164);"><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);"> </span><span class="" style="font-variant-ligatures: no-common-ligatures;">default</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);">:</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"> </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 40, 164);">break</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"> }</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">}</span></div></div></div></div></div><div class=""><br class=""></div><div class="">And here is the proposed switch statement with optional binding:</div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 40, 164);">switch</span><span class="" style="font-variant-ligatures: no-common-ligatures;"> </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 40, 164);">let</span><span class="" style="font-variant-ligatures: no-common-ligatures;"> parisCityID = </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);">cityIDs</span><span class="" style="font-variant-ligatures: no-common-ligatures;">[</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(212, 45, 10);">"Paris"</span><span class="" style="font-variant-ligatures: no-common-ligatures;">] {</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"> </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 40, 164);">case</span><span class="" style="font-variant-ligatures: no-common-ligatures;"> </span><span class="" style="font-size: 12px; line-height: normal; font-family: 'Fira Code'; font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);">0</span><span class="" style="font-variant-ligatures: no-common-ligatures;">..<</span><span class="" style="font-size: 12px; line-height: normal; font-family: 'Fira Code'; font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);">10</span><span class="" style="font-variant-ligatures: no-common-ligatures;">:</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"> print(</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(212, 45, 10);">"Paris city ID: </span><span class="" style="font-variant-ligatures: no-common-ligatures;">\</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(212, 45, 10);">(</span><span class="" style="font-variant-ligatures: no-common-ligatures;">parisCityID</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(212, 45, 10);">)"</span><span class="" style="font-variant-ligatures: no-common-ligatures;">)</span></div><div class="" style="margin: 0px; line-height: normal; color: rgb(187, 40, 164);"><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);"> </span><span class="" style="font-variant-ligatures: no-common-ligatures;">default</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);">:</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"> </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 40, 164);">break</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">}</span></div></div></div></div></div><div class=""><br class=""></div><div class="">With <font color="#bb28a4" face="Menlo" class=""><span class="" style="font-size: 11px;">var</span></font>:</div><div class=""><br class=""></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; line-height: normal; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 40, 164);">switch</span><span class="" style="font-variant-ligatures: no-common-ligatures;"> </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 40, 164);">var</span><span class="" style="font-variant-ligatures: no-common-ligatures;"> parisCityID = </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);">cityIDs</span><span class="" style="font-variant-ligatures: no-common-ligatures;">[</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(212, 45, 10);">"Paris"</span><span class="" style="font-variant-ligatures: no-common-ligatures;">] {</span><span class="" style="font-variant-ligatures: no-common-ligatures;"></span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"> </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 40, 164);">case</span><span class="" style="font-variant-ligatures: no-common-ligatures;"> </span><span class="" style="font-size: 12px; line-height: normal; font-family: 'Fira Code'; font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);">0</span><span class="" style="font-variant-ligatures: no-common-ligatures;">..<</span><span class="" style="font-size: 12px; line-height: normal; font-family: 'Fira Code'; font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);">10</span><span class="" style="font-variant-ligatures: no-common-ligatures;">:</span></div><div class="" style="margin: 0px; line-height: normal; color: rgb(0, 134, 0);"><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);"> parisCityID += </span><span class="" style="font-size: 12px; line-height: normal; font-family: 'Fira Code'; font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);">2</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);"> </span><span class="" style="font-variant-ligatures: no-common-ligatures;">// just to demonstrate var</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"> print(</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(212, 45, 10);">"Paris city ID: </span><span class="" style="font-variant-ligatures: no-common-ligatures;">\</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(212, 45, 10);">(</span><span class="" style="font-variant-ligatures: no-common-ligatures;">parisCityID</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(212, 45, 10);">)"</span><span class="" style="font-variant-ligatures: no-common-ligatures;">)</span></div><div class="" style="margin: 0px; line-height: normal; color: rgb(187, 40, 164);"><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);"> </span><span class="" style="font-variant-ligatures: no-common-ligatures;">default</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);">:</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"> </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 40, 164);">break</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">}</span></div><div class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"><br class=""></span></div></div></div></div><div class="">Feedback welcomed!</div></body></html>