Skip to content

Instantly share code, notes, and snippets.

@juliofruta
Last active August 8, 2016 22:58
Show Gist options
  • Save juliofruta/a5fe525f5d5bd1f9060639f71e0601e2 to your computer and use it in GitHub Desktop.
Save juliofruta/a5fe525f5d5bd1f9060639f71e0601e2 to your computer and use it in GitHub Desktop.
Avoid button targets in Swift 2.2
class Button : UIButton {
private var _action : (()->())?
var action : ()->() {
get {
return _action!
}
set (newAction) {
_action = newAction
self.addTarget(self,
action: #selector(Button.actionCaller),
forControlEvents: UIControlEvents.TouchUpInside)
}
}
@objc func actionCaller() {
self._action!()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment