YYTimer.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //
  2. // YYTimer.h
  3. // YYKit <https://github.com/ibireme/YYKit>
  4. //
  5. // Created by ibireme on 15/2/7.
  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 <Foundation/Foundation.h>
  12. NS_ASSUME_NONNULL_BEGIN
  13. /**
  14. YYTimer is a thread-safe timer based on GCD. It has similar API with `NSTimer`.
  15. YYTimer object differ from NSTimer in a few ways:
  16. * It use GCD to produce timer tick, and won't be affected by runLoop.
  17. * It make a weak reference to the target, so it can avoid retain cycles.
  18. * It always fire on main thread.
  19. */
  20. @interface YYTimer : NSObject
  21. + (YYTimer *)timerWithTimeInterval:(NSTimeInterval)interval
  22. target:(id)target
  23. selector:(SEL)selector
  24. repeats:(BOOL)repeats;
  25. - (instancetype)initWithFireTime:(NSTimeInterval)start
  26. interval:(NSTimeInterval)interval
  27. target:(id)target
  28. selector:(SEL)selector
  29. repeats:(BOOL)repeats NS_DESIGNATED_INITIALIZER;
  30. @property (readonly) BOOL repeats;
  31. @property (readonly) NSTimeInterval timeInterval;
  32. @property (readonly, getter=isValid) BOOL valid;
  33. - (void)invalidate;
  34. - (void)fire;
  35. @end
  36. NS_ASSUME_NONNULL_END