Created
February 22, 2017 10:06
-
-
Save dbrockman/385acfbf8c963919f8ef19aeaed0d953 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// | |
// TargetClosure is a bridge from closures to objc targets/selectors | |
// Create a TargetClosure with a closure and pass it as the target, then pass target.selector as the selector. | |
// | |
// Example: | |
// | |
// let target = TargetClosure { doYourThing() } | |
// oldSchoolFunction(target: target, action: target.selector) | |
// | |
public class TargetClosure { | |
public let selector: Selector | |
private let action: () -> Void | |
init(_ closure: @escaping () -> Void) { | |
selector = #selector(run) | |
action = closure | |
} | |
@objc public func run() { | |
action() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment