Last active
July 11, 2016 18:51
-
-
Save MathieuWhite/2946d57d862162041ef11433cfc356f1 to your computer and use it in GitHub Desktop.
A new way to do selectors in Swift 2.2.
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
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