NSObject (HHBlockPerform): delayed block executions
September 15, 2009 04:53 PM
| Cocoa, Development, Mac
| Permalink
typedef void (^HHPerformBlock)(id owner);
@interface NSObject (HHBlockPerform)
- (void)performAfterDelay:(NSTimeInterval)delay block:(HHPerformBlock)block;
@end
@implementation NSObject (HHBlockPerform)
- (void)performAfterDelay:(NSTimeInterval)delay block:(HHPerformBlock)block
{
[self performSelector:@selector(runBlock:) withObject:[block copy] afterDelay:delay];
}
- (void)runBlock:(HHPerformBlock)block
{
block(self);
[block release];
}
@end
@interface NSObject (HHBlockPerform)
- (void)performAfterDelay:(NSTimeInterval)delay block:(HHPerformBlock)block;
@end
@implementation NSObject (HHBlockPerform)
- (void)performAfterDelay:(NSTimeInterval)delay block:(HHPerformBlock)block
{
[self performSelector:@selector(runBlock:) withObject:[block copy] afterDelay:delay];
}
- (void)runBlock:(HHPerformBlock)block
{
block(self);
[block release];
}
@end
Comments (1)