<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=""><br class=""><div><blockquote type="cite" class=""><div class="">Le 7 janv. 2016 à 20:02, Joe Groff &lt;<a href="mailto:jgroff@apple.com" class="">jgroff@apple.com</a>&gt; a écrit :</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=us-ascii" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jan 7, 2016, at 10:59 AM, Jacob Bandes-Storch via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="gmail_extra" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">&nbsp; &nbsp; &nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><b class="">do let</b><span class="Apple-converted-space">&nbsp;</span>value2 = somethingNonOptional()</div><br class="Apple-interchange-newline"></div></blockquote></div><br class=""><div class="">'case let' already works like this, by declaring a pattern 'let a' that unconditionally matches anything.</div><div class=""><br class=""></div><div class="">-Joe</div></div></div></blockquote></div><br class=""><div class="">Well, the compiler complains, and does not provide any nice suggestion.</div><div class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>// error</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>if let x = value...</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>// OK</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>let x = value</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>if …</div><div class=""><br class=""></div><div class="">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><div class=""><br class=""></div><div class="">Gwendal</div><div class=""><br class=""></div></body></html>