相关疑难解决方法(0)

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万
查看次数

长周期块应用

我在我的应用程序中遵循以下周期

var maxIterations: Int = 0

func calculatePoint(cn: Complex) -> Int {

    let threshold: Double = 2
    var z: Complex = .init(re: 0, im: 0)
    var z2: Complex = .init(re: 0, im: 0)
    var iteration: Int = 0

    repeat {
        z2 = self.pow2ForComplex(cn: z)
        z.re = z2.re + cn.re
        z.im = z2.im + cn.im
        iteration += 1
    } while self.absForComplex(cn: z) <= threshold && iteration < self.maxIterations

    return iteration
}
Run Code Online (Sandbox Code Playgroud)

并在循环执行期间显示彩虹轮。如何管理该应用仍在响应UI操作?注意:在循环运行时,我在代码的不同部分更新了NSProgressIndicator,该代码未更新(未显示进度)。我怀疑这与调度有关,但是我对此相当“绿色”。我非常感谢您的帮助。谢谢。

nsprogressindicator dispatch-async swift3

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