Clock

A mechanism in which to measure time, and delay work until a given point in time.

iOS
16.0+
macOS
13.0+
tvOS
16.0+
watchOS
9.0+
protocol Clock<Duration> : Sendable
Browse conforming types

Types that conform to the Clock protocol define a concept of “now” which is the specific instant in time that property is accessed. Any pair of calls to the now property may have a minimum duration between them - this minimum resolution is exposed by the minimumResolution property to inform any user of the type the expected granularity of accuracy.

One of the primary uses for clocks is to schedule task sleeping. This method resumes the calling task after a given deadline has been met or passed with a given tolerance value. The tolerance is expected as a leeway around the deadline. The clock may reschedule tasks within the tolerance to ensure efficient execution of resumptions by reducing potential operating system wake-ups. If no tolerance is specified (i.e. nil is passed in) the sleep function is expected to schedule with a default tolerance strategy.

For more information about specific clocks see ContinuousClock and SuspendingClock.