Created
January 4, 2014 11:17
-
-
Save tangyumeng/8254351 to your computer and use it in GitHub Desktop.
performBlockAfterDelay
This file contains 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 <Foundation/Foundation.h> | |
@interface NSObject (PerformBlockAfterDelay) | |
// Perform something after a slight delay | |
- (void)performBlock:(void (^)(void))block afterDelay:(NSTimeInterval)delay; | |
@end | |
#import "NSObject+PerformBlockAfterDelay.h" | |
@implementation NSObject (PerformBlockAfterDelay) | |
// Perform something after a slight delay | |
- (void)performBlock:(void (^)(void))block afterDelay:(NSTimeInterval)delay { | |
// Copy the block | |
block = [block copy]; | |
// Perform the block after a delay | |
[self performSelector:@selector(fireBlockAfterDelay:) withObject:block afterDelay:delay]; | |
} | |
// Do the block! | |
- (void)fireBlockAfterDelay:(void (^)(void))block { | |
block(); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment