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

QQ Mail 286224043 at qq.com
Mon Jan 4 06:45:56 CST 2016


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160104/13088085/attachment.html>


More information about the swift-evolution mailing list