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!).")
    }

发布了94 篇原创文章 · 获赞 4 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/u011728344/article/details/78692543