Skip to content

Instantly share code, notes, and snippets.

@fluidsonic
Last active December 22, 2016 13:32
Show Gist options
  • Save fluidsonic/6f6359d871c8d1e9a793 to your computer and use it in GitHub Desktop.
Save fluidsonic/6f6359d871c8d1e9a793 to your computer and use it in GitHub Desktop.
Converting a closure to an @escaping closure in Swift 3
func makeEscaping<Parameters,Result>(_ closure: (Parameters) -> Result) -> (Parameters) -> Result {
func cast<From,To>(_ instance: From) -> To {
return (instance as Any) as! To
}
return cast(closure)
}
// Example
import UIKit
extension UIView {
static func noescapeAnimate(withDuration duration: TimeInterval, changes: () -> ()) {
animate(withDuration: duration, animations: makeEscaping(changes))
}
}
@fluidsonic
Copy link
Author

Fixed to support builds having Whole Module Optimization enabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment