[swift-evolution] extend trailing closure rule
Rimantas Liubertas
rimantas at gmail.com
Wed Jun 8 14:29:55 CDT 2016
>
> 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 (file:///Users/rimliu/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.iOS.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_DataTypes/index.html#//apple_ref/swift/tdef/c:@T@NSTimeInterval),
animations animations: () -> Void (file:///Users/rimliu/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.iOS.docset/Contents/Resources/Documents/documentation/Swift/Reference/Swift_StandardLibrary_TypeAliases/index.html#//apple_ref/swift/tdef/s:s4Void))
class func animateWithDuration(_ duration: NSTimeInterval (file:///Users/rimliu/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.iOS.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_DataTypes/index.html#//apple_ref/swift/tdef/c:@T@NSTimeInterval),
animations animations: () -> Void (file:///Users/rimliu/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.iOS.docset/Contents/Resources/Documents/documentation/Swift/Reference/Swift_StandardLibrary_TypeAliases/index.html#//apple_ref/swift/tdef/s:s4Void),
completion completion: ((Bool (file:///Users/rimliu/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.iOS.docset/Contents/Resources/Documents/documentation/Swift/Reference/Swift_Bool_Structure/index.html#//apple_ref/swift/struct/s:Sb)) -> Void (file:///Users/rimliu/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.iOS.docset/Contents/Resources/Documents/documentation/Swift/Reference/Swift_StandardLibrary_TypeAliases/index.html#//apple_ref/swift/tdef/s:s4Void))?)
class func animateWithDuration(_ duration: NSTimeInterval (file:///Users/rimliu/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.iOS.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_DataTypes/index.html#//apple_ref/swift/tdef/c:@T@NSTimeInterval),
delay delay: NSTimeInterval (file:///Users/rimliu/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.iOS.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_DataTypes/index.html#//apple_ref/swift/tdef/c:@T@NSTimeInterval),
options options: UIViewAnimationOptions (file:///Users/rimliu/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.iOS.docset/Contents/Resources/Documents/documentation/UIKit/Reference/UIView_Class/index.html#//apple_ref/swift/struct/c:@E@UIViewAnimationOptions),
animations animations: () -> Void (file:///Users/rimliu/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.iOS.docset/Contents/Resources/Documents/documentation/Swift/Reference/Swift_StandardLibrary_TypeAliases/index.html#//apple_ref/swift/tdef/s:s4Void),
completion completion: ((Bool (file:///Users/rimliu/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.iOS.docset/Contents/Resources/Documents/documentation/Swift/Reference/Swift_Bool_Structure/index.html#//apple_ref/swift/struct/s:Sb)) -> Void (file:///Users/rimliu/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.iOS.docset/Contents/Resources/Documents/documentation/Swift/Reference/Swift_StandardLibrary_TypeAliases/index.html#//apple_ref/swift/tdef/s:s4Void))?)
so your version is valid.
Best regards,
Rimantas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160608/fc08d17a/attachment.html>
More information about the swift-evolution
mailing list