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