<div dir="ltr">I see I spoke to soon. Indeed there is a warning &quot;&#39;if&#39; condition is always true&quot; when you use <b>only</b> &quot;if case let x = nonOptional()&quot; with no actual conditions. That&#39;s good, but as you said, leaves us without a solution for the original problem (in the case where you&#39;re not trying to mix it with optionals).<div><br></div><div>As much as I think &quot;do let&quot; makes sense:</div><div><br></div><div><div>    do let x = somethingNonOptional() {</div><div>        // use x</div><div>    }</div><div><br></div><div>It&#39;s worth pointing out that this works today by just moving the brace around:</div></div><div><br></div><div><div>    do { let x = somethingNonOptional()</div><div>        // use x</div><div>    }</div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature"><div dir="ltr"><div>Jacob Bandes-Storch<br></div></div></div></div>
<br><div class="gmail_quote">On Thu, Jan 7, 2016 at 11:08 AM, Jacob Bandes-Storch <span dir="ltr">&lt;<a href="mailto:jtbandes@gmail.com" target="_blank">jtbandes@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I think you might have misunderstood Joe&#39;s suggestion — it does work for me. Here&#39;s an example:<div><br></div><div><div>    if let y = somethingOptional(),</div><span class=""><div>        case let x = somethingNonOptional()</div></span><div>        where x != y</div><div>    {</div><div>        // Rejoice!</div><div>    }</div></div><span class="HOEnZb"><font color="#888888"><div><br></div></font></span><div class="gmail_extra"><span class="HOEnZb"><font color="#888888"><br clear="all"><div><div><div dir="ltr"><div>Jacob Bandes-Storch<br></div></div></div></div></font></span><div><div class="h5">
<br><div class="gmail_quote">On Thu, Jan 7, 2016 at 11:07 AM, Gwendal Roué <span dir="ltr">&lt;<a href="mailto:gwendal.roue@gmail.com" target="_blank">gwendal.roue@gmail.com</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><div><br><div><blockquote type="cite"><div>Le 7 janv. 2016 à 20:02, Joe Groff &lt;<a href="mailto:jgroff@apple.com" target="_blank">jgroff@apple.com</a>&gt; a écrit :</div><br><div><div style="word-wrap:break-word"><br><div><blockquote type="cite"><div>On Jan 7, 2016, at 10:59 AM, Jacob Bandes-Storch via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br><div><div class="gmail_extra" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">       <span> </span><b>do let</b><span> </span>value2 = somethingNonOptional()</div><br></div></blockquote></div><br><div>&#39;case let&#39; already works like this, by declaring a pattern &#39;let a&#39; that unconditionally matches anything.</div><div><br></div><div>-Joe</div></div></div></blockquote></div><br></div></div><div>Well, the compiler complains, and does not provide any nice suggestion.</div><div><br></div><div>I, and most code I’ve seen so far (including StackOverflow), solve this issue with an extra variable declared in the outer scope:</div><div><br></div><div><span style="white-space:pre-wrap">        </span>// error</div><div><span style="white-space:pre-wrap">        </span>if let x = value...</div><div><span style="white-space:pre-wrap">        </span></div><div><span style="white-space:pre-wrap">        </span>// OK</div><div><span style="white-space:pre-wrap">        </span>let x = value</div><div><span style="white-space:pre-wrap">        </span>if …</div><div><br></div><div>Remember the double role of `if let`: 1. unwrap the optional, 2. define a new variable, scoped to the `if` statement. We have 1, but not 2, and this is the gist of this thread.</div><span><font color="#888888"><div><br></div><div>Gwendal</div><div><br></div></font></span></div></blockquote></div><br></div></div></div></div>
</blockquote></div><br></div></div>