Last active
January 12, 2022 15:29
-
-
Save theocalmes/6809499 to your computer and use it in GitHub Desktop.
perform selector with blocks
This file contains hidden or 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
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 |
This file contains hidden or 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 "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