Skip to content

Instantly share code, notes, and snippets.

@tangyumeng
Created January 4, 2014 11:17
Show Gist options
  • Save tangyumeng/8254351 to your computer and use it in GitHub Desktop.
Save tangyumeng/8254351 to your computer and use it in GitHub Desktop.
performBlockAfterDelay
#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