Timer.scheduledTimer Swift 3与iOS 10之前的版本的兼容性 [英] Timer.scheduledTimer Swift 3 pre-iOS 10 compatibility

查看:152
本文介绍了Timer.scheduledTimer Swift 3与iOS 10之前的版本的兼容性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要安排一个计时器以每秒触发一次功能,但是我发现在Xcode 8 beta 3中,chedchedTimer仅适用于iOS 10.

I need to schedule a Timer for firing a function every second but I see that in Xcode 8 beta 3 the scheduledTimer is only available for iOS 10.

在iOS 9或更早版本中是否可以使用计时器?

Is there any alternative for using the timer in iOS 9 or previous versions?

Timer.scheduledTimer(withTimeInterval: 1, repeats: true, block: { (timer) in print("Hi!")})

推荐答案

已使用

Timer.scheduledTimer(timeInterval: 1,
                           target: self,
                         selector: #selector(self.updateTime),
                         userInfo: nil,
                          repeats: true)

这篇关于Timer.scheduledTimer Swift 3与iOS 10之前的版本的兼容性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆