Skip to content

Instantly share code, notes, and snippets.

@Thomvis
Last active February 6, 2024 20:25
  • Star 23 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Thomvis/b378f926b6e1a48973f694419ed73aca 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
}
@jbarros35
Copy link

its pretty useful thanks

@Stebulis
Copy link

Very useful indeed

@denniskeithgaso
Copy link

Very useful. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment