Skip to content

shien7654321/STWeakTimer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

STWeakTimer

Language Platform Version License

An alternative to NSTimer.

STWeakTimer is an alternative to NSTimer, it does not cause the retain cycle, it is thread-safe.

STWeakTimerPreview01

Requirements

  • iOS 8.0 or later (For iOS 8.0 before, maybe it can work, but I have not tested.)
  • ARC

Installation

STWeakTimer is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'STWeakTimer'

Usage

Import headers in your source files

In the source files where you need to use the library, import the header file:

#import <STWeakTimer/STWeakTimer.h>

Initialize STWeakTimer

Initialize a STWeakTimer, you can use a selector or block as the callback. You can also set the thread to execute the callback:

STWeakTimer *timer = [STWeakTimer scheduledTimerWithTimeInterval:1 userInfo:nil repeats:YES dispatchQueue:dispatch_get_main_queue() handler:^(STWeakTimer * _Nullable timer) {
    NSLog(@"Timer triggered");
}];

Control STWeakTimer

STWeakTimer supports pause and resume:

[timer pause];
[timer resume];

Author

Suta, shien7654321@163.com

License

MIT license.