Swift 4.0中对 GCD定时器的写法做了很多改进,使之更符合Swift的语言特点,比OC的语法看起来是简明清晰了不少
/// GCD定时器倒计时⏳
/// - timeInterval: 循环间隔时间
/// - repeatCount: 重复次数
/// - handler: 循环事件, 闭包参数: 1. timer, 2. 剩余执行次数
public func DispatchTimer(timeInterval: Double, repeatCount:Int, handler:@escaping (DispatchSourceTimer?, Int)->())
{
if repeatCount <= 0 {
return
}
let timer = DispatchSource.makeTimerSource