这个库为 NSTimer 提供了一个分类。您不需要手动调用 timer 中的 invalidate 方法,这样可以避免由循环引用导致的内存泄漏。
安装
NSTimer 支持使用 CocoaPods 在项目中安装库。
Podfile
要使用 CocoaPods 将 NSTimer 集成到您的 Xcode 项目中,请在您的 Podfile
中指定它:
source 'https://github.com/CocoaPods/Specs.git'
target 'TargetName' do
pod 'WTTimer'
end
然后,运行以下命令:
$ pod install
用法
与系统原生方法相同,您也不需要手动调用 timer 中的 invalidate 方法,
NSTimer *timer = [NSTimer wt_scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(log) userInfo:nil repeats:YES];
[timer invalidate]; // Not necessary