/BlocksKit/NSTimer+BlocksKit.m

http://github.com/zwaldowski/BlocksKit · Objective C · 29 lines · 18 code · 7 blank · 4 comment · 0 complexity · 0a9aafbb89fd5b1d16ddef4bddd537fa MD5 · raw file

  1. //
  2. // NSTimer+BlocksKit.m
  3. // BlocksKit
  4. //
  5. #import "NSTimer+BlocksKit.h"
  6. @interface NSTimer (BlocksKitPrivate)
  7. + (void)_executeBlockFromTimer:(NSTimer *)aTimer;
  8. @end
  9. @implementation NSTimer (BlocksKit)
  10. + (id)scheduledTimerWithTimeInterval:(NSTimeInterval)inTimeInterval block:(BKTimerBlock)block repeats:(BOOL)inRepeats {
  11. NSParameterAssert(block);
  12. return [self scheduledTimerWithTimeInterval:inTimeInterval target:self selector:@selector(_executeBlockFromTimer:) userInfo:[[block copy] autorelease] repeats:inRepeats];
  13. }
  14. + (id)timerWithTimeInterval:(NSTimeInterval)inTimeInterval block:(BKTimerBlock)block repeats:(BOOL)inRepeats {
  15. NSParameterAssert(block);
  16. return [self timerWithTimeInterval:inTimeInterval target:self selector:@selector(_executeBlockFromTimer:) userInfo:[[block copy] autorelease] repeats:inRepeats];
  17. }
  18. + (void)_executeBlockFromTimer:(NSTimer *)aTimer {
  19. NSTimeInterval time = [aTimer timeInterval];
  20. ((BKTimerBlock)aTimer.userInfo)(time);
  21. }
  22. @end