NSTimer的坑

这有三个API都是新增的,标识有API_AVAILABLE(macosx(10.12), ios(10.0), watchos(3.0), tvos(10.0))。

  • .+ (NSTimer *)timerWithTimeInterval:(NSTimeInterval)interval repeats:(BOOL)repeats block:(void (^)(NSTimer *timer))block;

  • . + (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)interval repeats:(BOOL)repeats block:(void (^)(NSTimer *timer))block;

  • .- (instancetype)initWithFireDate:(NSDate *)date interval:(NSTimeInterval)interval repeats:(BOOL)repeats block:(void (^)(NSTimer *timer))block;

特别是前两个,跟以下api一时手快容易混淆,容易让使用低于10.0系统的用户直接闪退,报错unrecognized selector;

  • .+ (NSTimer *)timerWithTimeInterval:(NSTimeInterval)ti invocation:(NSInvocation *)invocation repeats:(BOOL)yesOrNo;

  • .+ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)ti invocation:(NSInvocation *)invocation repeats:(BOOL)yesOrNo;

  • .+ (NSTimer *)timerWithTimeInterval:(NSTimeInterval)ti target:(id)aTarget selector:(SEL)aSelector userInfo:(nullable id)userInfo repeats:(BOOL)yesOrNo;

  • .+ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)ti target:(id)aTarget selector:(SEL)aSelector userInfo:(nullable id)userInfo repeats:(BOOL)yesOrNo;

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1.NSTimer的介绍 (1.)8种创建方法 <1> + (NSTimer *)timerWithTimeInt...
    liangZhen阅读 12,197评论 0 6
  • 一. NSTimer NSTimer的初始化方法有以下几种: 会自动启动, 并加入* MainRunloop*的*...
    codeshow阅读 3,532评论 0 0
  • 之前要做一个发送短信验证码的倒计时功能,打算用NSTimer来实现,做的过程中发现坑还是有不少的。 基本使用 NS...
    WeiHing阅读 9,824评论 1 8
  • NSTimer在IOS开发中会经常用到,尤其是小型游戏,然而对于初学者时常会注意不到其中的内存释放问题,将其基本用...
    zhong_JF阅读 3,715评论 0 0
  • 三:团队管理--辅导篇 1,认识辅导 1.1)定义:辅助,指导 辅导是随机的,一对一的,非正式的 1.2)好处 辅...
    罗津津CHANDO阅读 2,910评论 0 0

友情链接更多精彩内容