123456789101112131415161718192021222324252627282930313233 |
- //
- // Timer+LWPlayer.swift
- // SwiftBilibili
- //
- // Created by 罗文 on 2021/4/2.
- // Copyright © 2021年 罗文. All rights reserved.
- //
- import Foundation
- public extension Timer {
- class func scheduledTimerWithTimeInterval(_ timeInterval: TimeInterval, block: ()->(), repeats: Bool) -> Timer {
- return self.scheduledTimer(timeInterval: timeInterval, target: self, selector: #selector(Timer.executeBlockWithTimer(_:)), userInfo: AnyObject.self, repeats: repeats)
- }
-
- class func timerWithTimeInterval(_ timeInterval: TimeInterval, block: ()->(), repeats: Bool) -> Timer {
- return Timer(timeInterval: timeInterval, target: self, selector: #selector(Timer.executeBlockWithTimer(_:)), userInfo: AnyObject.self, repeats: repeats)
- }
-
- @objc private class func executeBlockWithTimer(_ timer: Timer) {
- // let block: ()->() = timer.userInfo as! ()->()
- // block()
- }
-
- static func executeOnMainQueueAfterTimeInterval(_ seconds: TimeInterval,block: @escaping ()->()) {
- executeAfterTimeInterval(seconds, queue: DispatchQueue.main, block: block)
- }
-
- static func executeAfterTimeInterval(_ seconds: TimeInterval, queue: DispatchQueue, block: @escaping ()->()) {
- let time = DispatchTime.now() + Double(Int64(seconds * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)
- queue.asyncAfter(deadline: time, execute: block)
- }
- }
|