ZYGCDTimer
ZYGCDTimer 主要用于替代 NSTimer
,不会强持有 target,基于 MSWeakTimer 进行修改的,本质上是个 GCD
定时器。
Features
- 弱引用
target
-
target
销毁之后,自动调用invalidate
- 支持
block
创建定时器 - 支持设置
GCD queue
- 支持暂停定时器
Example
下载 demo 直接运行即可
Requirements
- iOS 8.0+
- macOS 10.12+
Installation
ZYGCDTimer 支持 CocoaPods 安装。在 Podfile
中写入以下文本,然后执行 pod install
即可:
pod "ZYGCDTimer"
Usage
使用 target-selector
创建定时器
+ (instancetype)timerWithTimeInterval:(NSTimeInterval)interval
target:(id)aTarget
selector:(SEL)aSelector
userInfo:(nullable id)userInfo
repeats:(BOOL)repeats
dispatchQueue:(dispatch_queue_t)dispatchQueue;
使用 block
创建定时器
+ (instancetype)timerWithTimeInterval:(NSTimeInterval)interval
userInfo:(nullable id)userInfo
repeats:(BOOL)repeats
dispatchQueue:(dispatch_queue_t)dispatchQueue
block:(void (^)(ZYGCDTimer *timer))block;
启用定时器
- (void)fire;
无效定时器
- (void)invalidate;
暂停定时器
- (void)pause;
Author
ripperhe, [email protected]
License
ZYGCDTimer is available under the MIT license. See the LICENSE file for more info.