-
-
Save teologov/7ff17e4c7baee81a3b8a6dd818eec2d7 to your computer and use it in GitHub Desktop.
An easy way of dealing with dispatch time in Swift 3 (from https://github.com/Thomvis/BrightFutures/blob/xcode8b5/BrightFutures/Number+BrightFutures.swift)
This file contains hidden or 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
public extension Int { | |
public var seconds: DispatchTimeInterval { | |
return DispatchTimeInterval.seconds(self) | |
} | |
public var second: DispatchTimeInterval { | |
return seconds | |
} | |
public var milliseconds: DispatchTimeInterval { | |
return DispatchTimeInterval.milliseconds(self) | |
} | |
public var millisecond: DispatchTimeInterval { | |
return milliseconds | |
} | |
} | |
public extension DispatchTimeInterval { | |
public var fromNow: DispatchTime { | |
return DispatchTime.now() + self | |
} | |
} | |
// Example: | |
DispatchQueue.main.asyncAfter(deadline: 3.seconds.fromNow) { | |
// do something | |
} | |
// Instead of: | |
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + DispatchTimeInterval.seconds(3)) { | |
// do something | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment