[swift-evolution] extend trailing closure rule
Matt Neuburg
matt at tidbits.com
Wed Jun 8 17:11:05 CDT 2016
Well, I guess I didn't pick a strong enough case. Try this one:
UIView.animate(withDuration:0.4, delay: 0, options: [.autoreverse]) {
self.view.backgroundColor = UIColor.red()
}
That doesn't compile. I'm suggesting that it would be cool if it did. m.
> On Jun 8, 2016, at 12:29 PM, Rimantas Liubertas <rimantas at gmail.com> wrote:
>
>>
>> That's ugly. I'd rather write:
>>
>> UIView.animate(withDuration:0.4) {
>> self.v.backgroundColor = UIColor.red()
>> }
>>
>> What stops me is that `animations:` is not eligible for trailing closure syntax, because it isn't the last parameter — `completion:` is.
>
> Actually you can. UIView has three signatures ‘animateWithduration’:
>
> class func animateWithDuration(_ duration: NSTimeInterval,
> animations animations: () -> Void)
>
> class func animateWithDuration(_ duration: NSTimeInterval,
> animations animations: () -> Void,
> completion completion: ((Bool) -> Void)?)
>
> class func animateWithDuration(_ duration: NSTimeInterval,
> delay delay: NSTimeInterval,
> options options: UIViewAnimationOptions,
> animations animations: () -> Void,
> completion completion: ((Bool) -> Void)?)
>
> so your version is valid.
>
>
> Best regards,
> Rimantas
--
matt neuburg, phd = http://www.apeth.net/matt/
pantes anthropoi tou eidenai oregontai phusei
Programming iOS 9! http://shop.oreilly.com/product/0636920044352.do
iOS 9 Fundamentals! http://shop.oreilly.com/product/0636920044345.do
RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html
More information about the swift-evolution
mailing list