2019-07-22 Timer Swift var timer: Timer! timer = Timer.scheduledTimer(withTimeInterval: 0.5, repeats: true, block: { (_) in self.perform() }) func perform() { // some process if XXX { // time to end the Timer timer.invalidate() } }