NSTimer+TUISafe.m 602 B

123456789101112131415161718192021
  1. //
  2. // NSTimer+TUISafe.m
  3. // TUICore
  4. //
  5. // Created by wyl on 2022/7/5.
  6. // Copyright © 2023 Tencent. All rights reserved.
  7. //
  8. #import "NSTimer+TUISafe.h"
  9. @implementation NSTimer (TUISafe)
  10. + (NSTimer *)tui_scheduledTimerWithTimeInterval:(NSTimeInterval)interval repeats:(BOOL)repeats block:(void (^)(NSTimer *timer))block {
  11. return [self scheduledTimerWithTimeInterval:interval target:self selector:@selector(tui_callBlock:) userInfo:[block copy] repeats:repeats];
  12. }
  13. + (void)tui_callBlock:(NSTimer *)timer {
  14. void (^block)(NSTimer *timer) = timer.userInfo;
  15. !block ?: block(timer);
  16. }
  17. @end