Skip to content

Instantly share code, notes, and snippets.

@theocalmes
Last active January 12, 2022 15:29
Show Gist options
  • Save theocalmes/6809499 to your computer and use it in GitHub Desktop.
Save theocalmes/6809499 to your computer and use it in GitHub Desktop.
perform selector with blocks
typedef void(^TCVoidBlock)(void);
@interface NSObject (TCBlocks)
- (void)performBlock:(TCVoidBlock)block afterDelay:(NSTimeInterval)delay;
- (void)performBlockInBackground:(TCVoidBlock)block;
- (void)performBlockOnMainThread:(TCVoidBlock)block waitUntilDone:(BOOL)wait;
@end
#import "NSObject+TCBlocks.h"
@implementation NSObject (TCBlocks)
- (void)performBlock:(TCVoidBlock)block
{
block();
}
- (void)performBlock:(TCVoidBlock)block afterDelay:(NSTimeInterval)delay
{
[self performSelector:@selector(performBlock:) withObject:[block copy] afterDelay:delay];
}
- (void)performBlockInBackground:(TCVoidBlock)block
{
[self performSelectorInBackground:@selector(performBlock:) withObject:[block copy]];
}
- (void)performBlockOnMainThread:(TCVoidBlock)block waitUntilDone:(BOOL)wait
{
[self performSelectorOnMainThread:@selector(performBlock:) withObject:[block copy] waitUntilDone:wait];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment