- (instancetype)initWithFireDate:(NSDate *)date interval:(NSTimeInterval)ti target:(id)t selector:(SEL)s userInfo:(nullable id)ui repeats:(BOOL)rep;
//若date爲
[NSDate distantPast] 馬上啓動 若爲[NSDate distantFuture] 直到調用fire才啓動
//需要 [[NSRunLoop mainRunLoop]addTimer:self.timer forMode:NSDefaultRunLoopMode];
+ (NSTimer *)timerWithTimeInterval:(NSTimeInterval)ti target:(id)aTarget selector:(SEL)aSelector userInfo:(nullable id)userInfo repeats:(BOOL)yesOrNo;
//需要 [[NSRunLoop mainRunLoop]addTimer:self.timer forMode:NSDefaultRunLoopMode];
//加入即運行,通過fireDate進行暫停、開啓操作
demo:
self.timer = [NSTimer timerWithTimeInterval:2.0 target:self selector:@selector(printTimer) userInfo:nil repeats:YES];
[[NSRunLoop mainRunLoop]addTimer:self.timer forMode:NSDefaultRunLoopMode];
+ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)ti target:(id)aTarget selector:(SEL)aSelector userInfo:(nullable id)userInfo repeats:(BOOL)yesOrNo;
//不需要顯示加入主循環
+ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)ti invocation:(NSInvocation *)invocation repeats:(BOOL)yesOrNo;
//不需要顯示加入主循環
//啓動
@property (copy) NSDate *fireDate;
//定時器的啓動時間 1、[NSDate distantPast] 馬上啓動;2、 [NSDate distantFuture]永不啓動,可用於暫停。
@property (readonly) NSTimeInterval timeInterval; //獲取時間間隔
- (void)invalidate; //移除定時器,無法恢復