What is replacement of NSTimer.scheduledTimerWithTimeInterval() in swift 3? What is replacement of NSTimer.scheduledTimerWithTimeInterval() in swift 3? swift swift

What is replacement of NSTimer.scheduledTimerWithTimeInterval() in swift 3?


Try like this:

Timer.scheduledTimer(timeInterval: 0.35, target: self, selector: #selector(createEnemy), userInfo: nil, repeats: true)


You may also used with instance of Timer, if you want to invalidate as per your requirement.

//Create Timer instancevar objTimer = Timer()//Schedule Timerself.objTimer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(timerTriggered), userInfo: nil, repeats: true)//Invalidate Timer after task completeself.objTimer.invalidate()