From be00e9cb845f77d55d3565e9658fba53926f08e7 Mon Sep 17 00:00:00 2001 From: Ryan McLeod Date: Wed, 29 Jun 2016 16:31:39 -0700 Subject: [PATCH] Add NSTimer reference as block param --- NSTimer+Block/NSTimer+Block.h | 6 +++--- NSTimer+Block/NSTimer+Block.m | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/NSTimer+Block/NSTimer+Block.h b/NSTimer+Block/NSTimer+Block.h index a063dc2..d2b852c 100644 --- a/NSTimer+Block/NSTimer+Block.h +++ b/NSTimer+Block/NSTimer+Block.h @@ -17,7 +17,7 @@ @param block The block to be executed when the timer fire. The block should take no parameters and have no return value. @return The receiver, initialized such that, when added to a run loop, it will fire at date and then, if repeats is YES, every seconds after that. */ -- (instancetype)initWithFireDate:(NSDate *)date interval:(NSTimeInterval)seconds repeats:(BOOL)repeats block:(void (^)(void))block; +- (instancetype)initWithFireDate:(NSDate *)date interval:(NSTimeInterval)seconds repeats:(BOOL)repeats block:(void (^)(NSTimer*))block; /** Creates and returns a new NSTimer object and schedules it on the current run loop in the default mode. @@ -26,7 +26,7 @@ @param block The block to be executed when the timer fire. The block should take no parameters and have no return value. @return A new NSTimer object, configured according to the specified parameters. */ -+ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)seconds repeats:(BOOL)repeats block:(void (^)(void))block; ++ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)seconds repeats:(BOOL)repeats block:(void (^)(NSTimer*))block; /** Creates and returns a new NSTimer object initialized with the specified block. @@ -34,6 +34,6 @@ @param repeats If YES, the timer will repeatedly reschedule itself until invalidated. If NO, the timer will be invalidated after it fires. @param block The block to be executed when the timer fire. The block should take no parameters and have no return value. */ -+ (NSTimer *)timerWithTimeInterval:(NSTimeInterval)seconds repeats:(BOOL)repeats block:(void (^)(void))block; ++ (NSTimer *)timerWithTimeInterval:(NSTimeInterval)seconds repeats:(BOOL)repeats block:(void (^)(NSTimer*))block; @end diff --git a/NSTimer+Block/NSTimer+Block.m b/NSTimer+Block/NSTimer+Block.m index 34c9ffa..18ccc00 100644 --- a/NSTimer+Block/NSTimer+Block.m +++ b/NSTimer+Block/NSTimer+Block.m @@ -9,17 +9,17 @@ @implementation NSTimer (Block) -- (instancetype)initWithFireDate:(NSDate *)date interval:(NSTimeInterval)seconds repeats:(BOOL)repeats block:(void (^)(void))block +- (instancetype)initWithFireDate:(NSDate *)date interval:(NSTimeInterval)seconds repeats:(BOOL)repeats block:(void (^)(NSTimer*))block { return [self initWithFireDate:date interval:seconds target:self.class selector:@selector(runBlock:) userInfo:block repeats:repeats]; } -+ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)seconds repeats:(BOOL)repeats block:(void (^)(void))block ++ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)seconds repeats:(BOOL)repeats block:(void (^)(NSTimer*))block { return [self scheduledTimerWithTimeInterval:seconds target:self selector:@selector(runBlock:) userInfo:block repeats:repeats]; } -+ (NSTimer *)timerWithTimeInterval:(NSTimeInterval)seconds repeats:(BOOL)repeats block:(void (^)(void))block ++ (NSTimer *)timerWithTimeInterval:(NSTimeInterval)seconds repeats:(BOOL)repeats block:(void (^)(NSTimer*))block { return [self timerWithTimeInterval:seconds target:self selector:@selector(runBlock:) userInfo:block repeats:repeats]; } @@ -30,8 +30,8 @@ + (void)runBlock:(NSTimer *)timer { if ([timer.userInfo isKindOfClass:NSClassFromString(@"NSBlock")]) { - void (^block)(void) = timer.userInfo; - block(); + void (^block)(NSTimer*) = timer.userInfo; + block(timer); } }