ZYGCDTimer
ZYGCDTimer 主要用于替代 NSTimer
,不会强持有 target,基于 MSWeakTimer 进行修改的,本质上是个 GCD
定时器。
特性
- 弱引用
target
- 当
target
被销毁后,自动调用invalidate
- 支持以
block
的方式创建定时器 - 支持设置
GCD queue
- 支持暂停定时器
示例
下载 demo 直接运行即可
需求
- iOS 8.0+
- macOS 10.12+
安装
ZYGCDTimer 支持通过 CocoaPods 安装。在 Podfile
中写入以下文本,然后执行 pod install
即可:
pod "ZYGCDTimer"
使用说明
使用 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;
作者
ripperhe, [email protected]
许可证
ZYGCDTimer 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。