works on swift5.0
var timer = Timer()
var secondsPassed = 0
var totalTime = 300
timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(self.update), userInfo: nil, repeats: true)
@objc func update() {
if secondsPassed < totalTime{
secondsPassed += 1
}else{
timer.invalidate()
print("Time's up")
}