小编Der*_*eck的帖子

DispatchSourceTimer和Swift 3.0

我无法弄清楚如何在Swift 3.0中重复调度计时器.我的代码:

let queue = DispatchQueue(label: "com.firm.app.timer",
                          attributes: DispatchQueue.Attributes.concurrent)
let timer = DispatchSource.makeTimerSource(flags: DispatchSource.TimerFlags(rawValue: UInt(0)),
                                           queue: queue)

timer.scheduleRepeating(deadline: DispatchTime.now(),
                        interval: .seconds(5),
                        leeway: .seconds(1)
)

timer.setEventHandler(handler: {
     //a bunch of code here
})

timer.resume()
Run Code Online (Sandbox Code Playgroud)

计时器只会触发一次并且不会像它应该的那样重复.我怎样才能解决这个问题?

dispatch grand-central-dispatch swift swift3

23
推荐指数
1
解决办法
2万
查看次数

标签 统计

dispatch ×1

grand-central-dispatch ×1

swift ×1

swift3 ×1