Created
November 7, 2018 00:43
-
-
Save sprhawk/7c522ae4142c6bc3bd9aaf6a6efb208f to your computer and use it in GitHub Desktop.
Make Int convertible to DispatchTime or DispatchTimeInterval
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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