NSTimer+YYAdd.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //
  2. // NSTimer+YYAdd.h
  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 <Foundation/Foundation.h>
  12. NS_ASSUME_NONNULL_BEGIN
  13. /**
  14. Provides extensions for `NSTimer`.
  15. */
  16. @interface NSTimer (YYAdd)
  17. /**
  18. Creates and returns a new NSTimer object and schedules it on the current run
  19. loop in the default mode.
  20. @discussion After seconds seconds have elapsed, the timer fires,
  21. sending the message aSelector to target.
  22. @param seconds The number of seconds between firings of the timer. If seconds
  23. is less than or equal to 0.0, this method chooses the
  24. nonnegative value of 0.1 milliseconds instead.
  25. @param block The block to invoke when the timer fires. The timer maintains
  26. a strong reference to the block until it (the timer) is invalidated.
  27. @param repeats If YES, the timer will repeatedly reschedule itself until
  28. invalidated. If NO, the timer will be invalidated after it fires.
  29. @return A new NSTimer object, configured according to the specified parameters.
  30. */
  31. + (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)seconds block:(void (^)(NSTimer *timer))block repeats:(BOOL)repeats;
  32. /**
  33. Creates and returns a new NSTimer object initialized with the specified block.
  34. @discussion You must add the new timer to a run loop, using addTimer:forMode:.
  35. Then, after seconds have elapsed, the timer fires, invoking
  36. block. (If the timer is configured to repeat, there is no need
  37. to subsequently re-add the timer to the run loop.)
  38. @param seconds The number of seconds between firings of the timer. If seconds
  39. is less than or equal to 0.0, this method chooses the
  40. nonnegative value of 0.1 milliseconds instead.
  41. @param block The block to invoke when the timer fires. The timer instructs
  42. the block to maintain a strong reference to its arguments.
  43. @param repeats If YES, the timer will repeatedly reschedule itself until
  44. invalidated. If NO, the timer will be invalidated after it fires.
  45. @return A new NSTimer object, configured according to the specified parameters.
  46. */
  47. + (NSTimer *)timerWithTimeInterval:(NSTimeInterval)seconds block:(void (^)(NSTimer *timer))block repeats:(BOOL)repeats;
  48. @end
  49. NS_ASSUME_NONNULL_END