// // PollTool.swift // PaiAi // // Created by zhengjianfei on 2017/4/7. // Copyright © 2017年 yb. All rights reserved. // import UIKit class PollTool: NSObject { var timer : DispatchSourceTimer? = nil var count = 0 func start() { } func stop() { } func restart() { } func configureTime(event handler : @escaping (()->())) { timer = DispatchSource.makeTimerSource(queue: DispatchQueue.main) timer?.setEventHandler(handler: {[weak self] in if let weakself = self { weakself.count += 1 if weakself.count == 20 { weakself.count = 0 handler() } } }) timer?.resume() } }