KSTTimer

@interface KSTTimer : NSObject

KSTTimer is a replacement for NSTimer that supports blocks and does not retain its target.

  • Returns whether the timer is valid and capable of firing. This will be NO if the timer has been invalidated using the invalidate method.

    Declaration

    Objective-C

    @property (readonly, getter=isValid) BOOL valid;
  • Returns the userInfo object that passed in on initialization.

    Declaration

    Objective-C

    @property (nonatomic, strong, readonly, nullable) id userInfo;
  • Sets the allowable tolerance for the timer, meaning how much the system can adjust the fire time of the timer to optimize energy usage.

    Declaration

    Objective-C

    @property NSTimeInterval tolerance;
  • Creates and returns a timer using initWithTimeInterval:target:selector:userInfo:repeats:queue:, passing nil for queue, and calls schedule on it.

    Declaration

    Objective-C

    + (nonnull instancetype)scheduledTimerWithTimeInterval:
                                (NSTimeInterval)timeInterval
                                                    target:(nonnull id)target
                                                  selector:(nonnull SEL)selector
                                                  userInfo:(nullable id)userInfo
                                                   repeats:(BOOL)repeats;
  • Creates and returns a timer using initWithTimeInterval:target:selector:userInfo:repeats:queue: and calls schedule on it.

    Declaration

    Objective-C

    + (nonnull instancetype)
        scheduledTimerWithTimeInterval:(NSTimeInterval)timeInterval
                                target:(nonnull id)target
                              selector:(nonnull SEL)selector
                              userInfo:(nullable id)userInfo
                               repeats:(BOOL)repeats
                                 queue:(nullable dispatch_queue_t)queue;
  • Creates and returns a timer using initWithTimeInterval:block:userInfo:repeats:queue: and calls schedule on it.

    Declaration

    Objective-C

    + (nonnull instancetype)
        scheduledTimerWithTimeInterval:(NSTimeInterval)timeInterval
                                 block:(nonnull KSTTimerBlock)block
                              userInfo:(nullable id)userInfo
                               repeats:(BOOL)repeats
                                 queue:(nullable dispatch_queue_t)queue;
  • Creates and returns a timer that will invoke the provided selector on target when it fires.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithTimeInterval:(NSTimeInterval)timeInterval
                                          target:(nonnull id)target
                                        selector:(nonnull SEL)selector
                                        userInfo:(nullable id)userInfo
                                         repeats:(BOOL)repeats;

    Parameters

    timeInterval

    The interval at which the timer should fire

    target

    The target on which to invoke selector

    selector

    The selector to invoke on target

    userInfo

    The user info to associate with the timer

    repeats

    Whether the timer should repeat

    Return Value

    The initialized timer

  • Creates and returns a timer that will invoke the provided selector on target when it fires.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithTimeInterval:(NSTimeInterval)timeInterval
                                          target:(nonnull id)target
                                        selector:(nonnull SEL)selector
                                        userInfo:(nullable id)userInfo
                                         repeats:(BOOL)repeats
                                           queue:(nullable dispatch_queue_t)queue;

    Parameters

    timeInterval

    The interval at which the timer should fire

    target

    The target on which to invoke selector

    selector

    The selector to invoke on target

    userInfo

    The user info to associate with the timer

    repeats

    Whether the timer should repeat

    queue

    The queue on which to fire the timer, pass nil to use the main queue

    Return Value

    The initialized timer

  • Creates and returns a timer that will invoke a block when it fires.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithTimeInterval:(NSTimeInterval)timeInterval
                                           block:(nonnull KSTTimerBlock)block
                                        userInfo:(nonnull id)userInfo
                                         repeats:(BOOL)repeats
                                           queue:(nullable dispatch_queue_t)queue;

    Parameters

    timeInterval

    The interval at which the timer should fire

    block

    The block to invoke when the timer fires

    userInfo

    The user info to associate with the timer

    repeats

    Whether the timer should repeat

    queue

    The queue on which to fire the timer, pass nil to use the main queue

    Return Value

    The initialized timer

  • Unavailable

    Undocumented

    Declaration

    Objective-C

    - (instancetype)init NS_UNAVAILABLE;
  • Unavailable

    Undocumented

    Declaration

    Objective-C

    + (instancetype)new NS_UNAVAILABLE;
  • Schedules the receiver to fire. Calling this on a timer that has already been scheduled does nothing.

    Declaration

    Objective-C

    - (void)schedule;
  • Fires the timer synchronously on the calling queue. If called on a repeating timer, its regular schedule will not be interrupted. If called on a non-repeating timer, it will invalidate itself after firing.

    Declaration

    Objective-C

    - (void)fire;
  • Cancels a scheduled timer and prevents it from firing again. This method can be called from any thread.

    Declaration

    Objective-C

    - (void)invalidate;