[swift-evolution] [Proposal]: support disable to trailing closure syntax

Alex Migicovsky migi at apple.com
Mon Jan 4 11:26:34 CST 2016


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!).

- Alex

> On Jan 4, 2016, at 4:45 AM, QQ Mail via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Hi, All: 
> 	trailing closure is good for most cases, but sometimes it is also make code unclear, for example: 
> 	
> UIView.animateWithDuration(0.3, animations: { () -> Void in
>     // animation code here
>     }) { (Bool) -> Void in
>         // completion code here
> }
> 
> the label been removed and the code also not aligned well. 
> I would like to write like this: 
> 
> UIView.animateWithDuration(0.3,
>     
>     animations: { () -> Void in
>         // animation code here
>     },
>     completion: { Bool -> Void in
>         // completion code here
>     }
> )
> 
> It is possible, just every time you have to write it manually. It’s a little wast.
> So I have a thought, since we already know this function is not well suit for trailing 
> closure, can we add a attribute to disable it, for example: 
> 
> extension UIView {
> 
>     @disable_trailing_closure
>     public static func animateWithDuration(duration:NSTimeInterval, animations:()->Void, completion:()->Void) {
>         // implementations ...
>     }
> }
> 
> I also found another one have issue for this too. link: http://www.natashatherobot.com/swift-trailing-closure-syntax/ <http://www.natashatherobot.com/swift-trailing-closure-syntax/>
> what do you think?
> 
> Best Regards
> 
> ChenYungui
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160104/49542769/attachment.html>


More information about the swift-evolution mailing list