Swift 4 Timer Crashes with NSException

前端 未结 3 852
借酒劲吻你
借酒劲吻你 2021-01-03 07:45

I\'ve been searching for a way to use a Timer in Swift 4 and looked at this article. I test out my code in xcode and when the the timer first ticks (in this case after 10 se

3条回答
  •  不知归路
    2021-01-03 08:34

    Try this in swift 4

    import UIKit
    
    class ViewController: UIViewController {
    
        var timer: Timer!
    
        override func viewDidLoad() {
           super.viewDidLoad()
    
    
            self.timer = Timer.scheduledTimer(timeInterval: 10, target: self, selector: #selector(self.updateValue), userInfo: nil, repeats: true)
        }
    
        func updateValue(){
    
            print("Timer is call")
        }
    }
    

提交回复
热议问题