private var timer: dispatch_source_t? = nil@H_403_9@
private func startTimer() {@H_403_9@
let updateInterval: UInt64 = 1@H_403_9@
let interval = updateInterval * NSEC_PER_SEC@H_403_9@
let leeway: UInt64 = 300000000 // UInt64(0.3) * interval@H_403_9@
let queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0)@H_403_9@
@H_403_9@
timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER,0,queue)@H_403_9@
if timer != nil {@H_403_9@
dispatch_source_set_timer(timer!,dispatch_walltime(nil,0),interval,leeway)@H_403_9@
dispatch_source_set_event_handler(timer!,{ () -> Void in@H_403_9@
self.checkNewScreenshot()@H_403_9@
})@H_403_9@
}@H_403_9@
dispatch_resume(timer!)@H_403_9@
}@H_403_9@
@H_403_9@
private func stopTimer() {@H_403_9@
if timer != nil {@H_403_9@
dispatch_suspend(timer!)@H_403_9@
dispatch_resume(timer!)@H_403_9@
timer = nil@H_403_9@
}@H_403_9@
}@H_403_9@ 原文链接:https://www.f2er.com/swift/325402.html