I can’t start my SWIFT 3 timer

I used timers before and they worked, but since NSTimer was changed to Timer, my timer refused to work. The code I tried is as follows:

override func viewDidLoad() {
super.viewDidLoad()

_ = Timer(timeInterval: 3, target: self, selector: #selector (test), userInfo: nil, repeats: true)

}

func test() {
print("The timer worked")
}

The test function is never called, I don’t know why. I also tried to initialize it and use it like this:

var followUpTimer:Timer! 

override func viewDidLoad() {
super.viewDidLoad()

followUpTimer = Timer(timeInterval: 3, target: self, selector: #selector(test) , userInfo: nil, repeats: true)

}

func test() {
print("The timer worked")
}

But this doesn't work either. What am I doing wrong? All the answers I found on the Internet indicate that this is the correct approach.

(NS)Timer requires A running loop can work properly. You can add a timer to the loop programmatically, but it is more convenient to use this method

Timer.scheduledTimer(withTimeInterval:. ..

I have used timers before and they worked, but since NSTimer was changed to Timer, my timer refused to work. The code I tried is as follows:

override func viewDidLoad() {
super.viewDidLoad()

_ = Timer(timeInterval: 3, target: self, selector: #selector(test), userInfo: nil, repeats: true)

}

func test() {
print("The timer worked ")
}

The test function is never called, I don’t know why. I also tried to initialize it and use it like this:

var followUpTimer:Timer!

override func viewDidLoad() {
super.viewDidLoad()

followUpTimer = Timer(timeInterval: 3, target: self, selector : #selector(test), userInfo: nil, repeats: true)

}

func test() {
print("The timer worked")< br />}

But it doesn’t work either. What am I doing wrong? All the answers I found on the Internet indicate that this is the right approach.

(NS)Timer needs a running cycle The loop can work properly. You can add a timer to the loop programmatically, but it is more convenient to use this method

Timer.scheduledTimer(withTimeInterval:... 

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 4167 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.