Last active
August 29, 2015 14:01
-
-
Save cbaltzer/32dde814d8b77ee3d30f to your computer and use it in GitHub Desktop.
A convenient dispatch_after() category
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
/* NSObject+BlockDelay.h */ | |
#import <Foundation/Foundation.h> | |
@interface NSObject (BlockDelay) | |
- (void)performBlock:(void (^)(void))block afterDelay:(NSTimeInterval)delay; | |
@end | |
/* NSObject+BlockDelay.m */ | |
#import "NSObject+BlockDelay.h" | |
@implementation NSObject (BlockDelay) | |
- (void)performBlock:(void (^)(void))block afterDelay:(NSTimeInterval)delay { | |
dispatch_time_t delay_time = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC)); | |
dispatch_after(delay_time, dispatch_get_main_queue(), block); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated to a category instead of a macro, based on this implementation.