RVS_BasicGCDTimer

public class RVS_BasicGCDTimer

This is a general-purpose GCD timer class.

It requires that an owning instance register a delegate to receive callbacks.

The way that you use this, is to create an instance of this class (we use a class, to ensure that it is referenced, as opposed to copied). You then call resume() on that instance.

  • This is the time between fires, in seconds.

    Declaration

    Swift

    public var timeIntervalInSeconds: TimeInterval
  • This is how much leeway we give the timer, in milliseconds. It is ignored for onlyFireOnce.

    Declaration

    Swift

    public var leewayInMilliseconds: Int
  • This allows the delegate to add any context data to the instance,

    Declaration

    Swift

    public var context: Any!
  • This is the dispatch queue the timer will use.

    Declaration

    Swift

    public var queue: DispatchQueue!
  • True, if we are to use the Apple Wall Clock time.

    Declaration

    Swift

    public var isWallTime: Bool
  • Declaration

    Swift

    public var isInvalid: Bool { get }

    Return Value

    true, if the timer is invalid. READ ONLY

  • Declaration

    Swift

    public var isOnlyFiringOnce: Bool { get }

    Return Value

    true, if the timer will only fire one time (will return false after that one fire). READ ONLY

  • Declaration

    Swift

    public var isRunning: Bool { get set }

    Return Value

    true, if the timer is currently running. READ/WRITE

  • Declaration

    Swift

    public var delegate: RVS_BasicGCDTimerDelegate? { get set }

    Return Value

    the delegate object. READ/WRITE. If nil, then the instance will stop and invalidate. You must have a delegate to run.

  • Default constructor

    Declaration

    Swift

    public init(timeIntervalInSeconds inTimeIntervalInSeconds: TimeInterval,
                delegate inDelegate: RVS_BasicGCDTimerDelegate?,
                leewayInMilliseconds inLeewayInMilliseconds: Int = 0,
                onlyFireOnce inOnlyFireOnce: Bool = false,
                context inContext: Any! = nil,
                queue inQueue: DispatchQueue! = nil,
                isWallTime inIsWallTime: Bool = false)

    Parameters

    timeIntervalInSeconds

    The time (in seconds) between fires.

    delegate

    Our delegate, for callbacks. Optional. Default is nil.

    leewayInMilliseconds

    Any leeway. This is optional, and default is zero (0). It is ignored if onlyFireOnce is true.

    onlyFireOnce

    If true, then this will only fire one time, as opposed to repeat. Optional. Default is false. If true, then leewayInMilliseconds is ignored.

    context

    This can be any data that the caller wants to associate with the timer. It will be available in the callback, as the timer object’s context property.

    queue

    The DispatchQueue to use for the timer. Optional. If not specified, the default queue is used.

    isWallTime

    If true (default is false), then the timer will use the Apple Wall time clock, which is more consistent.

  • If the timer is not currently running, we resume. If running, nothing happens.

    Declaration

    Swift

    public func resume()
  • If the timer is currently running, we suspend. If not running, nothing happens.

    Declaration

    Swift

    public func pause()
  • This completely nukes the timer. It resets the entire object to default.

    Declaration

    Swift

    public func invalidate()