Timer

public extension Timer
  • schedule: Creates and schedules a one-time NSTimer instance.

    Note

    Timer doesn’t need to be invalidated after using this function.

    Seealso

    CFRunLoopTimerCreateWithHandler()

    Declaration

    Swift

    static func schedule(withDelay delay: TimeInterval, handler: @escaping (CFRunLoopTimer?) -> Void) -> Timer

    Parameters

    delay

    The delay before execution.

    handler

    A closure to execute after delay.

    Return Value

    The newly-created NSTimer instance.

  • schedule: Creates and schedules a repeating NSTimer instance.

    Warning

    Timer should be invalidated after using this function. Use timer.invalidate()

    Declaration

    Swift

    static func schedule(repeatInterval interval: TimeInterval, handler: @escaping (CFRunLoopTimer?) -> Void) -> Timer

    Parameters

    repeatInterval

    The interval between each execution of handler. Note that individual calls may be delayed; subsequent calls to handler will be based on the time the NSTimer was created.

    handler

    A closure to execute after each repeatInterval.

    Return Value

    The newly-created NSTimer instance.