I\'m trying to create an NSTimer
in Swift
but I\'m having some trouble.
NSTimer(timeInterval: 1, target: self, selector: test(), us
Here's a quick example on how to use the Selector
class on Swift:
override func viewDidLoad() {
super.viewDidLoad()
var rightButton = UIBarButtonItem(title: "Title", style: UIBarButtonItemStyle.Plain, target: self, action: Selector("method"))
self.navigationItem.rightBarButtonItem = rightButton
}
func method() {
// Something cool here
}
Note that if the method passed as a string doesn't work, it will fail at runtime, not compile time, and crash your app. Be careful