Created
July 5, 2011 16:45
-
-
Save brunogama/1065235 to your computer and use it in GitHub Desktop.
NSTimer blocks implementation //NOT WORKING.
This file contains 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
#import <Foundation/Foundation.h> | |
typedef void (^VoidBlock)(); | |
@interface NSTimer (NSTimer_Additions) | |
+ (NSTimer *)scheduleTimerWithTimeInterval:(NSTimeInterval)theSeconds repeats:(BOOL)repeats actions:(VoidBlock)actions; | |
@end |
This file contains 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
#import "NSTimer+Additions.h" | |
static VoidBlock _voidBlock; | |
@interface NSTimer (AdditionsPrivate) // Private stuff | |
- (void)theBlock; | |
@end | |
@implementation NSTimer (NSTimer_Additions) | |
+ (NSTimer *)scheduleTimerWithTimeInterval:(NSTimeInterval)theSeconds repeats:(BOOL)repeats actions:(VoidBlock)actions { | |
[_voidBlock release]; | |
_voidBlock = [actions copy]; | |
NSTimer* timer = [[NSTimer alloc] initWithFireDate:[NSDate date] | |
interval:theSeconds | |
target:self | |
selector:@selector(theBlock) | |
userInfo:nil | |
repeats:repeats]; | |
[timer fire]; | |
return [timer autorelease]; | |
} | |
- (void)theBlock { | |
_voidBlock(); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment