The initial value of the property (in your case: timer ) cannot depend on another property of the class (in your case: interval ).
Therefore, you need to move the timer = NSTimer(interval, ...) setting to a class method, for example. in viewDidLoad . As a result, timer should be defined as optional or implicitly deployed optional.
Note also that Selector(...) takes a literal string as an argument, not the method itself.
So this should work:
class ViewController: UIViewController { var interval : NSTimeInterval = 1.0 var timer : NSTimer! func timerRedraw() { } override func viewDidLoad() { super.viewDidLoad() timer = NSTimer(timeInterval: interval, target: self, selector: Selector("timerRedraw"), userInfo: nil, repeats: true)
Martin R Sep 15 '14 at 19:31 2014-09-15 19:31
source share