Skip to content
This repository has been archived by the owner on Feb 2, 2018. It is now read-only.

Add NSTimer reference as block parameter #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions NSTimer+Block/NSTimer+Block.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -26,14 +26,14 @@
@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.
@param seconds The number of seconds between firings of the timer. If seconds is less than or equal to 0.0, this method chooses the nonnegative value of 0.1 milliseconds instead.
@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
10 changes: 5 additions & 5 deletions NSTimer+Block/NSTimer+Block.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand All @@ -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);
}
}

Expand Down