At the moment an optional closure is considered escaping so you don’t have to state it using @escaping and as you see you actually can’t. A bug or two exists against Swift related this and I don’t know their current state.<br><br>If after removing @escaping things still fail to compile please post a code example.<br><br>-Shawn<br><div class="gmail_quote"><div dir="ltr">On Fri, Jan 5, 2018 at 1:17 PM Kenny Leung via swift-users &lt;<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>&gt; wrote:<br></div><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>Because it’s being assigned to an ivar, it’s forced to be escaping, or so the compiler tells me.</div></div><div style="word-wrap:break-word"><div><br></div><div>-Kenny</div></div><div style="word-wrap:break-word"><div><br></div><br><div><blockquote type="cite"><div>On Jan 5, 2018, at 12:04 PM, Kevin Nattinger &lt;<a href="mailto:swift@nattinger.net" target="_blank">swift@nattinger.net</a>&gt; wrote:</div><br class="m_-4407080695172136762Apple-interchange-newline"><div><div style="word-wrap:break-word">If you remove the @escaping you&#39;ll notice it doesn&#39;t complain about a non-escaping closure escaping.<div>I could be wrong, but I believe that&#39;s because using it as an associated value forces it to escape on the calling side.</div><div><br></div><div><div style="margin:0px;font-size:13px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><div style="margin:0px;line-height:normal;font-size:12px"><span style="color:#ba2da2">func</span> esc(<span style="color:#ba2da2">_</span> x: <span style="color:#ba2da2">@escaping</span> () -&gt; ()) {</div><div style="margin:0px;line-height:normal;font-size:12px">    x()</div><div style="margin:0px;line-height:normal;font-size:12px">}</div><div style="margin:0px;line-height:normal;font-size:12px"><span style="color:#ba2da2">func</span> noesc(<span style="color:#ba2da2">_</span> x: () -&gt; ()) {</div><div style="margin:0px;line-height:normal;font-size:12px">    x()</div><div style="margin:0px;line-height:normal;font-size:12px">}</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Helvetica;min-height:14px"><br></div><div style="margin:0px;line-height:normal;font-size:12px"><span style="color:#ba2da2">func</span> foo() {</div><div style="margin:0px;line-height:normal;font-size:12px">    <span style="color:#31595d">noesc</span> {</div><div style="margin:0px;line-height:normal;font-size:12px">        <span style="color:#3e1e81">print</span>(<span style="color:#4f8187">owner</span>) <span style="color:#008400">// compiles</span></div><div style="margin:0px;line-height:normal;font-size:12px">    }</div><div style="margin:0px;line-height:normal;font-size:12px">    <span style="color:#31595d">esc</span> {</div><div style="margin:0px;line-height:normal;color:rgb(0,132,0);font-size:12px"><span>        </span><span style="color:#3e1e81">print</span><span>(</span><span style="color:#4f8187">owner</span><span>) </span>// error: requires explicit &#39;self.&#39;…</div><div style="margin:0px;line-height:normal;font-size:12px">    }</div><div style="margin:0px;line-height:normal;font-size:12px">    <span style="color:#703daa">Optional</span>&lt;()-&gt;()&gt;.<span style="color:#3e1e81">some</span> {</div><div style="margin:0px;line-height:normal;color:rgb(0,132,0);font-size:12px"><span>        </span><span style="color:#3e1e81">print</span><span>(</span><span style="color:#4f8187">owner</span><span>) </span>// error: requires explicit &#39;self.&#39;…</div><div style="margin:0px;line-height:normal;font-size:12px">    }</div><div style="margin:0px;line-height:normal;font-size:12px">}</div><div><br></div></div></div><div><br><div><blockquote type="cite"><div>On Jan 5, 2018, at 11:48 AM, Kenny Leung via swift-users &lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt; wrote:</div><br class="m_-4407080695172136762Apple-interchange-newline"><div><div style="word-wrap:break-word">Hi All.<div><br></div><div>It seems that if you have an escaping closure argument, you can’t make it optional. Am I right?</div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)">    <span style="color:#ba2da2">init</span> (</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)">        owner:<span style="color:#703daa">AnyObject</span>,</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(112,61,170);background-color:rgb(255,255,255)"><span>        handler:</span><span style="color:#ba2da2">@escaping</span><span> (</span>HXObserverNotification<span>)-&gt;</span>Void</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)">        ) {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)">        <span style="color:#ba2da2">self</span>.owner = owner</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)">        <span style="color:#ba2da2">self</span>.handler = handler</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)">    }</div></div><div><br></div><div>You could try this:</div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)">    <span style="color:#ba2da2">init</span> (</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)">        owner:<span style="color:#703daa">AnyObject</span>,</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(112,61,170);background-color:rgb(255,255,255)"><span>        handler:</span><span style="color:#ba2da2">@escaping</span><span> ((</span>HXObserverNotification<span>)-&gt;</span>Void)?</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)">        ) {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)">        <span style="color:#ba2da2">self</span>.owner = owner</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)">        <span style="color:#ba2da2">self</span>.handler = handler</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)">    }</div></div><div>You get “@escaping attribute only applies to function types”</div><div><br></div><div>Or you could try this:</div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)">    <span style="color:#ba2da2">init</span> (</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)">        owner:<span style="color:#703daa">AnyObject</span>,</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(112,61,170);background-color:rgb(255,255,255)"><span>        handler:(</span><span style="text-decoration:underline">@</span><span style="text-decoration:underline;color:#ba2da2">escaping</span><span style="text-decoration:underline"> </span><span>(</span>HXObserverNotification<span>)-&gt;</span>Void<span>)?</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)">        ) {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)">        <span style="color:#ba2da2">self</span>.owner = owner</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)">        <span style="color:#ba2da2">self</span>.handler = handler</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)">    }</div></div><div>You get “@escaping attribute may only be used in function parameter position”</div><div><br></div><div>-Kenny</div><div><br></div><div><br></div></div>_______________________________________________<br>swift-users mailing list<br><a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-users" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a><br></div></blockquote></div><br></div></div></div></blockquote></div><br></div>_______________________________________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a><br>
</blockquote></div>