<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="">I think instead of an attribute I’d prefer rules that allow trailing closures at call sites. The most straightforward solution would be to only allow using trailing closures at the call site if the invoked function has a single closure that’s the last parameter. I think the only unfortunate aspect of that is it’s an implicit rule which makes it harder for new devs to learn (and experienced devs to remember!).<div class=""><br class=""></div><div class="">- Alex</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 4, 2016, at 4:45 AM, QQ Mail 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=""><meta http-equiv="Content-Type" content="text/html charset=gb2312" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi, All:&nbsp;<div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>trailing closure is good for most cases, but sometimes it is also make code unclear, for example:&nbsp;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">UIView</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">animateWithDuration</span>(<span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0.3</span>, animations: { () -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Void</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">in</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="" class="">&nbsp; &nbsp; </span>// animation code here</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; }) { (Bool) -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Void</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">in</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span>// completion code here</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div></div><div class=""><br class=""></div><div class="">the label been removed and the code also not aligned well.&nbsp;</div><div class="">I would like to write like this:&nbsp;</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(61, 29, 129);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">UIView</span><span style="" class="">.</span>animateWithDuration<span style="" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0.3</span><span style="" class="">,</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; animations: { () -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Void</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">in</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span>// animation code here</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; },</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; completion: { Bool -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Void</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">in</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span>// completion code here</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">)</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">It is possible, just every time you have to write it manually. It’s a little wast.</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">So I have a thought, since we already know this function is not well suit for trailing&nbsp;</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">closure, can we add a attribute to disable it, for example:&nbsp;</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><div style="margin: 0px; line-height: normal; color: rgb(187, 44, 162);" class="">extension<span style="" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">UIView</span><span style="" class=""> {</span></div><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">&nbsp; &nbsp; <font color="#ff2807" class="">@disable_trailing_closure</font></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">&nbsp; &nbsp; public</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">static</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> animateWithDuration(duration:<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">NSTimeInterval</span>, animations:()-&gt;<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Void</span>, completion:()-&gt;<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Void</span>) {</div><div style="margin: 0px; line-height: normal; color: rgb(0, 132, 0);" class=""><span style="" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span>// implementations ...</div><div style="margin: 0px; line-height: normal;" class="">&nbsp; &nbsp; }</div><div style="margin: 0px; line-height: normal;" class="">}</div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">I also found another one have issue for this too. link:&nbsp;<a href="http://www.natashatherobot.com/swift-trailing-closure-syntax/" class="">http://www.natashatherobot.com/swift-trailing-closure-syntax/</a></div><div style="margin: 0px; line-height: normal;" class="">what do you think?</div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">Best Regards</div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">ChenYungui</div></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=o7Sk0DkcYEKVmF-2FwdtorNjvlKoT8y8bu9b7eKifytJjLH-2B-2BigS4dFhziqyjNZHPc88NMklU3hxT3lC-2FnSFYOC9G46yw0O77Nq643QsBhb0DDg8IGGPQCiXTKldS2q95IWbC8VxQoml2RMmp6zIJU-2Fpg0CYTPbP5gr-2FzZNeJfUZBTjWGiNvXnIBesux-2Fxnk8wEtTiQ3r3BoHvdiwhupl-2Fdw-3D-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;" class="">
</div>
_______________________________________________<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=""></div></blockquote></div><br class=""></div></body></html>