Skip to content

Instantly share code, notes, and snippets.

@imoldman
Created February 10, 2014 06:45
Show Gist options
  • Save imoldman/8911441 to your computer and use it in GitHub Desktop.
Save imoldman/8911441 to your computer and use it in GitHub Desktop.
handy category for run some block on a NSThread
#import <Foundation/Foundation.h>
@interface NSThread (RunBlock)
- (void)performBlock:(void(^)())block;
- (void)performBlock:(void (^)())block afterDelay:(NSTimeInterval)delay;
@end
#import "NSThread+RunBlock.h"
@implementation NSThread (RunBlock)
- (void)performBlock:(void(^)())block
{
[self performSelector:@selector(onlyForRunBlock:) onThread:self withObject:block waitUntilDone:NO];
}
- (void)performBlock:(void (^)())block afterDelay:(NSTimeInterval)delay
{
[self performBlock:^{
[self performSelector:@selector(onlyForRunBlock:) withObject:block afterDelay:delay];
}];
}
- (void)onlyForRunBlock:(void(^)())block
{
block();
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment