iOS开发(Swift)——时间器(Timer)的使用

iOS开发交流群:301058503

  1. 全局变量的定义:var timer : Timer!
  2. 使用:timer=Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(self.textfieldNotification), userInfo: nil, repeats: true)
    textfieldNotification是timer的方法名

  3. 销毁:如果像OC一样直接timer.invalidate()会崩溃,要用
    guard let timer1 = self.timer
    else{ return }
    timer1.invalidate()

猜你喜欢

转载自blog.csdn.net/liumude123/article/details/54571895