Last active
December 22, 2016 13:32
-
-
Save fluidsonic/6f6359d871c8d1e9a793 to your computer and use it in GitHub Desktop.
Converting a closure to an @escaping closure in Swift 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fixed to support builds having
Whole Module Optimization
enabled.