Skip to content

Instantly share code, notes, and snippets.

@sprhawk
Created November 7, 2018 00:43
Show Gist options
  • Save sprhawk/7c522ae4142c6bc3bd9aaf6a6efb208f to your computer and use it in GitHub Desktop.
Save sprhawk/7c522ae4142c6bc3bd9aaf6a6efb208f to your computer and use it in GitHub Desktop.
Make Int convertible to DispatchTime or DispatchTimeInterval
import Foundation
protocol DispatchTimeIntervalConvertible {
func seconds() -> DispatchTimeInterval
func milliseconds() -> DispatchTimeInterval
func secondsFromNow() -> DispatchTime
func millisecondsFromNow() -> DispatchTime
}
extension Int : DispatchTimeIntervalConvertible {}
extension DispatchTimeIntervalConvertible where Self == Int {
func seconds() -> DispatchTimeInterval {
return DispatchTimeInterval.seconds(self)
}
func milliseconds() -> DispatchTimeInterval {
return DispatchTimeInterval.milliseconds(self)
}
func secondsFromNow() -> DispatchTime {
return DispatchTime.now() + self.seconds()
}
func millisecondsFromNow() -> DispatchTime {
return DispatchTime.now() + self.milliseconds()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment