RVS_BasicGCDTimer

public class RVS_BasicGCDTimer
extension RVS_BasicGCDTimer: Equatable

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 a completion function that can be used, instead of a delegate.

    Declaration

    Swift

    public typealias RVS_BasicGCDTimerCompletion = (RVS_BasicGCDTimer, Bool) -> Void

Public Instance Properties

  • If we don’t have a delegate, we should have a completion.

    Declaration

    Swift

    public var completion: RVS_BasicGCDTimerCompletion?
  • 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

Public Computed Properties

  • 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.

Public Methods

  • Default constructor

    Declaration

    Swift

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

    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 true. 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.

    completion

    If provided, this function will be called (not necessarily in the main thread), when the timer is complete, or aborts. Optional. Default is nil. > NOTE: completion is very simple. It is only called when the timer completes, or is aborted. For finer control, use a delegate.

  • Super-simple initializer (just the time and a completion). Both parameters are required.

    Declaration

    Swift

    public init(_ inTimeIntervalInSeconds: TimeInterval, completion inCompletion: @escaping RVS_BasicGCDTimerCompletion)

    Parameters

    inTimeIntervalInSeconds

    The time (in seconds) between fires.

    completion

    If provided, this function will be called (not necessarily in the main thread), when the timer is complete, or aborts. Optional. Default is nil.

  • 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()

Equatable Conformance

  • Simple comparison, using the instance UUIDs

    Declaration

    Swift

    public static func == (lhs: RVS_BasicGCDTimer, rhs: RVS_BasicGCDTimer) -> Bool

    Parameters

    lhs

    The left-hand side of the comparison.

    rhs

    The right-hand side.

    Return Value

    True, if both reference the same instance.