XBTimer
这是一个会自动销毁的定时器,如果所有者销毁了,或者定时器调用 stop 并且没有强引用定时器时,定时器会自动销毁
使用:
__weak TestViewController *weakSelf = self; [XBTimer timerStartWithTimeInterval:1 owner:self repeats:YES onMainThread:YES delay:NO block:^(XBTimer *timer) { __strong TestViewController *strongSelf = weakSelf; if (strongSelf->_count == 4) { [timer stop]; } NSLog(@"runTimerOnMainRunLoop"); strongSelf->_count++; }];