Skip to content

Instantly share code, notes, and snippets.

@Thomvis
Last active January 11, 2022 13:18
Embed
What would you like to do?
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
}
@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