Last active
May 17, 2017 10:33
-
-
Save faimin/ea02582967f4d69e26be42757287b74e to your computer and use it in GitHub Desktop.
resolve loop references in NSTimer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface NSTimer (ZDUtility) | |
+ (NSTimer *)zd_scheduledTimerWithTimeInterval:(NSTimeInterval)seconds | |
block:(void (^)(NSTimer *timer))block | |
repeats:(BOOL)repeats; | |
+ (NSTimer *)zd_timerWithTimeInterval:(NSTimeInterval)seconds | |
block:(void (^)(NSTimer *timer))block | |
repeats:(BOOL)repeats; | |
@end | |
@implementation NSTimer (ZDUtility) | |
#pragma mark - Public Method | |
+ (NSTimer *)zd_scheduledTimerWithTimeInterval:(NSTimeInterval)seconds block:(void (^)(NSTimer *timer))block repeats:(BOOL)repeats { | |
return [NSTimer scheduledTimerWithTimeInterval:seconds target:self selector:@selector(executeTimerBlock:) userInfo:[block copy] repeats:repeats]; | |
} | |
+ (NSTimer *)zd_timerWithTimeInterval:(NSTimeInterval)seconds block:(void (^)(NSTimer *timer))block repeats:(BOOL)repeats { | |
return [NSTimer timerWithTimeInterval:seconds target:self selector:@selector(executeTimerBlock:) userInfo:[block copy] repeats:repeats]; | |
} | |
#pragma mark - Private Method | |
+ (void)executeTimerBlock:(NSTimer *)timer { | |
if ([timer userInfo]) { | |
void(^timerBlock)(NSTimer *) = (void(^)(NSTimer *))[timer userInfo]; | |
timerBlock(timer); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment