-
-
Save idelfonsog2/b774d2c881525216ac7d27c1c0fe4c54 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 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