Skip to content

Instantly share code, notes, and snippets.

@donly
Created May 24, 2012 03:20
Show Gist options
  • Save donly/2779238 to your computer and use it in GitHub Desktop.
Save donly/2779238 to your computer and use it in GitHub Desktop.
// declare
@property (retain) NSTimer *unregisteredTimer;
// implements
- (IBAction)createUnregisteredTimer:sender {
NSMethodSignature *methodSignature = [self methodSignatureForSelector:@selector(invocationMethod:)];
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSignature];
[invocation setTarget:self];
[invocation setSelector:@selector(invocationMethod:)];
NSDate *startDate = [NSDate date];
[invocation setArgument:&startDate atIndex:2];
NSTimer *timer = [NSTimer timerWithTimeInterval:0.5 invocation:invocation repeats:YES];
self.unregisteredTimer = timer;
}
- (IBAction)startUnregisteredTimer:sender {
if (unregisteredTimer != nil) {
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
[runLoop addTimer:unregisteredTimer forMode:NSDefaultRunLoopMode];
}
}
- (IBAction)stopUnregisteredTimer:sender {
[unregisteredTimer invalidate];
self.unregisteredTimer = nil;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment