TimerHandler

public protocol TimerHandler : AnyObject

A TimerHandler represents a backend implementation of a Timer.

This type is an implementation detail and should not be used directly, unless implementing your own metrics backend. To use the SwiftMetrics API, please refer to the documentation of Timer.

Implementation requirements

To implement your own TimerHandler you should respect a few requirements that are necessary so applications work as expected regardless of the selected TimerHandler implementation.

  • The TimerHandler must be a class.
  • Record a duration in nanoseconds.

    Declaration

    Swift

    func recordNanoseconds(_ duration: Int64)

    Parameters

    value

    Duration to record.

  • preferDisplayUnit(_:) Default implementation

    Set the preferred display unit for this TimerHandler.

    Default Implementation

    Declaration

    Swift

    func preferDisplayUnit(_ unit: TimeUnit)

    Parameters

    unit

    A hint to the backend responsible for presenting the data of the preferred display unit. This is not guaranteed to be supported by all backends.