Skip to content

Instantly share code, notes, and snippets.

@Thomvis
Last active February 6, 2024 20:25
Show Gist options
  • Save Thomvis/b378f926b6e1a48973f694419ed73aca to your computer and use it in GitHub Desktop.
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
}
@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