Skip to content

Instantly share code, notes, and snippets.

@mbehan
Created November 1, 2018 13:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbehan/708b67552162aceff89679bdcf3728e6 to your computer and use it in GitHub Desktop.
Save mbehan/708b67552162aceff89679bdcf3728e6 to your computer and use it in GitHub Desktop.
extension UIControl.Event: Hashable{
public var hashValue: Int{
return Int(self.rawValue)
}
static func == (lhs: UIControl.Event, rhs: UIControl.Event) -> Bool{
return lhs.rawValue == rhs.rawValue
}
}
class Button: UIButton{
private class Actuator{
let action: ()->Void
init(action: @escaping ()->Void){
self.action = action
}
@objc func performAction(){
action()
}
}
private var actions = [UIControl.Event:Actuator]()
func on(_ event: UIControl.Event, perform action: @escaping ()->Void){
actions[event] = Actuator(action: action)
addTarget(actions[event], action: #selector(Actuator.performAction), for: event)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment