Timer

extension Timer
  • Create a timer that will fire just once after some interval has elapsed.

    Declaration

    Swift

    @discardableResult
    public class func once(after: TimeInterval, _ block: @escaping (Timer) -> Void) -> Timer

    Parameters

    after

    the duration to wait before firing

    block

    the closure to call when the timer fires

    Return Value

    new Timer instance

  • Create a timer that will fire just once at a given time.

    Declaration

    Swift

    @discardableResult
    public class func once(when: Date, _ block: @escaping (Timer) -> Void) -> Timer

    Parameters

    when

    the to fire

    block

    the closure to call when the timer fires

    Return Value

    new Timer instance

  • Create a timer that will fire repeatedly every N seconds.

    Declaration

    Swift

    @discardableResult
    public class func every(_ interval: TimeInterval, _ block: @escaping (Timer) -> Void) -> Timer

    Parameters

    interval

    the number of seconds between firings

    block

    the closure to call when the timer fires

    Return Value

    new Timer instance