我们有时启用一个定时器来做一些事情,比如计时等。
启用一个计数,60秒,停止
Var timer = Timer()
count = 0
timer = Timer.scheduledTimer(timeInterval:1, target: self, selector:#selector(ViewController.changevalue),userInfo:nil,repeats: true)
//这里的 viewcontroller可以用self代替。 Changevalue是你循环的函数名
Func changevalue() {
//代码
count += 1
if count > =60
timer.invalidate()
}