<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Yes, Thorsten.<div class=""><br class=""></div><div class="">Brent: I’m sorry if the title of the thread is not precise enough. The goal here is to let such a closure guarantee variable initialisation, as below:</div><div class=""><br class=""></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="color: rgb(187, 44, 162);"><span class="Apple-tab-span" style="white-space: pre;">        </span>func</span>&nbsp;f(<span class="" style="color: rgb(187, 44, 162);">@noescape</span>(<span class="" style="color: rgb(112, 61, 170);">once</span>) closure: () -&gt; ()) {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; &nbsp; closure()</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="Apple-tab-span" style="white-space: pre;">        </span>}</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><br class=""></div><div class="" style="font-family: Menlo; font-size: 11px; margin: 0px; line-height: normal; color: rgb(0, 132, 0);"><span class="" style="color: rgb(187, 44, 162);"><span class="Apple-tab-span" style="white-space: pre;">        </span>let</span><span class="" style="color: rgb(0, 0, 0);">&nbsp;x:&nbsp;</span><span class="" style="color: rgb(112, 61, 170);">Int</span><span class="" style="color: rgb(0, 0, 0);">&nbsp;&nbsp;</span>// Not initialized</div><div class="" style="font-family: Menlo; font-size: 11px; margin: 0px; line-height: normal;"><span class="" style="color: rgb(49, 89, 93);"><span class="Apple-tab-span" style="white-space: pre;">        </span>f</span>&nbsp;{&nbsp;<span class="" style="color: rgb(79, 129, 135);">x</span>&nbsp;=&nbsp;<span class="" style="color: rgb(39, 42, 216);">1</span>&nbsp;}</div><div class="" style="font-family: Menlo; font-size: 11px; margin: 0px; line-height: normal; color: rgb(0, 132, 0);"><span class="" style="color: rgb(61, 29, 129);"><span class="Apple-tab-span" style="white-space: pre;">        </span>print</span><span class="" style="color: rgb(0, 0, 0);">(</span><span class="" style="color: rgb(79, 129, 135);">x</span><span class="" style="color: rgb(0, 0, 0);">)&nbsp; &nbsp;&nbsp;</span>// Guaranteed to be initialized</div></div><div class=""><br class=""></div><div class="">Such closure can not escape. Hence @noescape(once), not @once.</div><div class=""><br class=""></div><div class="">dispatch_sync() is often cited in this mailing list, and we all want that it declares its argument as @noescape. Now it would be even better if it would declare it as @noescape(once).</div><div class=""><br class=""></div><div class="">Gwendal</div><div class=""><br class=""></div><div class=""><br class=""><blockquote type="cite" class="">Le 29 janv. 2016 à 13:11, Thorsten Seitz &lt;<a href="mailto:tseitz42@icloud.com" class="">tseitz42@icloud.com</a>&gt; a écrit :<br class=""><br class="">But if the closure can escape it is difficult to guarantee that it is executed at all (e.g. in your examples such as dispatch_async).<br class=""><br class="">-Thorsten<br class=""><br class="">Am 29. Januar 2016 um 11:58 schrieb Brent Royal-Gordon via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt;:<br class=""><br class=""><blockquote type="cite" class=""><blockquote type="cite" class="quoted-plain-text">You are right Jacob, a modifier `@noescape(once)` would be better, as it would help compiler distinguish between assignment and initialization of captured variables.<br class=""></blockquote><blockquote type="cite" class="quoted-plain-text"><br class=""></blockquote><blockquote type="cite" class="quoted-plain-text">The utility of such a new feature is maybe tiny, but clear: it extends the opportunities to declare variables before initializing them. The Swift 1 to 2 transition has already extended those&nbsp;opportunities, so we’re just following an existing trend, here.<br class=""></blockquote><br class="">I actually think that `once` is orthogonal to `noescape`. There are a *lot* of closures that are not noescape, but are called exactly once, such as dispatch_async and most completion&nbsp;handlers.<br class=""><br class="">--&nbsp;<br class="">Brent Royal-Gordon<br class="">Architechies<br class=""><br class="">_______________________________________________<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=""></blockquote></blockquote><br class=""></div></body></html>