- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个计时器:
let queue = DispatchQueue(label: "com.domain.app.timer")
timer = DispatchSource.makeTimerSource(queue: queue)
timer.schedule(deadline: .now(), repeating: 30.0, leeway: .seconds(0))
...
timer.resume()
除一件事外,它工作完美。计时器在我的 timer.resume() 之后执行第一次迭代。但是我需要在重复时间后执行第一次迭代(在我的例子中是 30 秒)。如何做到这一点?
最佳答案
deadline
参数决定首次投递时间(主题计时器合并、余地、...) 和 repeating
参数确定第一次交付后的间隔。
因此
timer.schedule(deadline: .now() + 30.0, repeating: 30.0, leeway: .seconds(0))
安排定时器在 30 秒后发送,然后每隔30 秒。
关于swift - DispatchSourceTimer 重复时间后如何执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49190656/
我有一个计时器: let queue = DispatchQueue(label: "com.domain.app.timer") timer = DispatchSource.makeTimerSo
我有一个奇怪的行为,即我的应用程序在返回到之前的 View Controller 后崩溃了。我有一个显示配置文件 Controller ,然后我去编辑配置文件 Controller 。我在那里录制了一
我正在尝试使用 DispatchSourceTimer 在另一个线程上运行重复计时器。这段代码在 Playground 上运行良好,但在我的 iOS 应用程序中,它总是在 deinit 方法上崩溃(或
我不知道如何让调度计时器在 Swift 3.0 中重复工作。我的代码: let queue = DispatchQueue(label: "com.firm.app.timer",
我不知道如何让调度计时器在 Swift 3.0 中重复工作。我的代码: let queue = DispatchQueue(label: "com.firm.app.timer",
我有一个正在运行的 DispatchSourceTimer 是用以下方法创建的: self.timer = DispatchSource.makeTimerSource(flags: .init(ra
我很难理解 DispatchSourceTimer 之间的主要区别, Timer和 asyncAfter (在我的例子中,调度一个需要每 X 秒运行一次的任务,尽管了解定时器的差异可能对有用)(或者除
我不知道如何让调度计时器在 Swift 3.0 中重复工作。我的代码: let queue = DispatchQueue(label: "com.firm.app.timer",
我是一名优秀的程序员,十分优秀!