Xcode9学习笔记78 - 使用Timer执行定时任务

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(ViewController.timerAction(_:)), userInfo: "Apple", repeats: true)
    }
    
    @objc func timerAction(_ timer:Timer) {
        let parameter = timer.userInfo
        print("I am eating \(parameter!).")
    }

  

posted on 2017-12-02 07:25  业余极客  阅读(501)  评论(0编辑  收藏  举报

导航