Skip to content

Instantly share code, notes, and snippets.

@MathieuWhite
Last active July 11, 2016 18:51
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 MathieuWhite/2946d57d862162041ef11433cfc356f1 to your computer and use it in GitHub Desktop.
Save MathieuWhite/2946d57d862162041ef11433cfc356f1 to your computer and use it in GitHub Desktop.
A new way to do selectors in Swift 2.2.
private extension Selector {
static let buttonPressed = #selector(ViewController.buttonPressed(_:))
}
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let button: UIButton = UIButton(type: UIButtonType.Custom)
button.addTarget(self,
action: .buttonPressed,
forControlEvents: UIControlEvents.TouchUpInside)
}
func buttonPressed(sender: UIButton) {
print("New selectors in Swift 2.2!")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment