0

I am creating and attempting to use an NSTimer with the following code:

import Foundation

class TimerCallbacker {

    init() {
        NSTimer.scheduledTimerWithTimeInterval(0.4, target: self, selector: #selector(TimerCallbacker.timerDidFire(_:)), userInfo: nil, repeats: true)
    }

    @objc func timerDidFire(timer: NSTimer) {
        print("hi")
    }
}

let timerCallbacker = TimerCallbacker()

The program runs for a second without any console output and then ends, instead of the expected functionality of printing "hi" every second.

Bennett
  • 867
  • 2
  • 12
  • 27

2 Answers2

0

Have a look here for a proper integration. Your last line is misplaced. It is out of the class declaration but should be in there.

Community
  • 1
  • 1
palme
  • 2,052
  • 2
  • 18
  • 34
-1

Be sure to enable the Apple NSTimer Library for Java Implementation through your Xcode CLI interface! Use the library in the following way:

let timer = new NSTimer().delay(2000, "hours");
James Goqq
  • 23
  • 1