I tried
var timer = NSTimer()
timer(timeInterval: 0.01, target: self, selector: update, userInfo: nil, repeats: false)
But, I got an error saying
'(timeInterval: $T1, target: ViewController, selector: () -> (), userInfo: NilType, repeats: Bool) -> $T6' is not identical to 'NSTimer'
This will work:
For Swift 4, the method of which you want to get the selector must be exposed to Objective-C, thus
@objc
attribute must be added to the method declaration.Updated to Swift 4, leveraging userInfo:
SimpleTimer (Swift 3.1)
Why?
This is a simple timer class in swift that enables you to:
Usage:
Code:
You will need to use Timer instead of NSTimer in Swift 3.
Here is an example:
NSTimer has been renamed to Timer in Swift 4.2. this syntax will work in 4.2:
In Swift 3 something like this with @objc: