newBie in swift。
如果用户停止应用程序或滑动以在计时器运行时停止应用程序。我是否需要垃圾收集计时器或停止计时器的位置。如果没有处理,会引起任何问题吗?
Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(self.setUpTimerCountDown), userInfo: nil, repeats: true)
由于
答案 0 :(得分:0)
import UIKit
class ViewController: UIViewController {
var timer: Timer!
override func viewDidLoad() {
super.viewDidLoad()
self.timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(self.updateValue), userInfo: nil, repeats: true)
}
override func viewWillDisappear(_ animated: Bool) {
if self.timer != nil{
self.timer.invaidate()
self.timer = nil
}
}
func updateValue(){
print("Timer is call")
}
}