NSTimer+YYAdd.m 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. //
  2. // NSTimer+YYAdd.m
  3. // YYKit <https://github.com/ibireme/YYKit>
  4. //
  5. // Created by ibireme on 14/15/11.
  6. // Copyright (c) 2015 ibireme.
  7. //
  8. // This source code is licensed under the MIT-style license found in the
  9. // LICENSE file in the root directory of this source tree.
  10. //
  11. #import "NSTimer+YYAdd.h"
  12. #import "YYKitMacro.h"
  13. YYSYNTH_DUMMY_CLASS(NSTimer_YYAdd)
  14. @implementation NSTimer (YYAdd)
  15. + (void)_yy_ExecBlock:(NSTimer *)timer {
  16. if ([timer userInfo]) {
  17. void (^block)(NSTimer *timer) = (void (^)(NSTimer *timer))[timer userInfo];
  18. block(timer);
  19. }
  20. }
  21. + (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)seconds block:(void (^)(NSTimer *timer))block repeats:(BOOL)repeats {
  22. return [NSTimer scheduledTimerWithTimeInterval:seconds target:self selector:@selector(_yy_ExecBlock:) userInfo:[block copy] repeats:repeats];
  23. }
  24. + (NSTimer *)timerWithTimeInterval:(NSTimeInterval)seconds block:(void (^)(NSTimer *timer))block repeats:(BOOL)repeats {
  25. return [NSTimer timerWithTimeInterval:seconds target:self selector:@selector(_yy_ExecBlock:) userInfo:[block copy] repeats:repeats];
  26. }
  27. @end