<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="">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 style="color: #000000" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #3e1e81" class="">print</span><span style="color: #000000" class="">(</span><span style="color: #4f8187" class="">owner</span><span style="color: #000000" 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 style="color: #000000" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #3e1e81" class="">print</span><span style="color: #000000" class="">(</span><span style="color: #4f8187" class="">owner</span><span style="color: #000000" 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><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" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" 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 style="" class="">&nbsp; &nbsp; &nbsp; &nbsp; handler:</span><span style="color: #ba2da2" class="">@escaping</span><span style="" class=""> (</span>HXObserverNotification<span style="" 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 style="" class="">&nbsp; &nbsp; &nbsp; &nbsp; handler:</span><span style="color: #ba2da2" class="">@escaping</span><span style="" class="">&nbsp;((</span>HXObserverNotification<span style="" 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 style="" 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 style="" class="">(</span>HXObserverNotification<span style="" class="">)-&gt;</span>Void<span style="" 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" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></div></blockquote></div><br class=""></div></body></html>