Last active
December 20, 2015 06:38
-
-
Save monjer/6086704 to your computer and use it in GitHub Desktop.
NSTimer block实现
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
| // | |
| // NSTimer+Block.h | |
| // Created by manjun.han on 23/06/2013. | |
| // | |
| typedef void (^TimerBlock)(NSTimeInterval time); | |
| @interface NSTimer (Block) | |
| + (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)seconds block:(TimerBlock) block repeats:(BOOL)repeats ; | |
| @end |
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
| // | |
| // NSTimer+Block.m | |
| // Created by manjun.han on 23/06/2013. | |
| // | |
| #import "NSTimer+Block.h" | |
| @interface NSTimer (BlockPrivite) | |
| + (void)exeBlockOfTimer:(NSTimer*)timer ; | |
| @end | |
| @implementation NSTimer (Block) | |
| + (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)seconds block:(TimerBlock) block repeats:(BOOL)repeats | |
| { | |
| return [self scheduledTimerWithTimeInterval:seconds target:self selector:@selector(exeBlockOfTimer:) userInfo:block repeats:repeats]; | |
| } | |
| + (void)exeBlockOfTimer:(NSTimer *)timer | |
| { | |
| NSTimeInterval time = [timer timeInterval]; | |
| TimerBlock block = [timer userInfo]; | |
| if (block){ | |
| block(time); | |
| } | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment