Skip to content

Instantly share code, notes, and snippets.

@idelfonsog2
Forked from Thomvis/DispatchTime.swift
Created April 1, 2017 03:29
Show Gist options
  • Save idelfonsog2/b774d2c881525216ac7d27c1c0fe4c54 to your computer and use it in GitHub Desktop.
Save idelfonsog2/b774d2c881525216ac7d27c1c0fe4c54 to your computer and use it in GitHub Desktop.
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