Skip to content

Instantly share code, notes, and snippets.

@cbaltzer
Last active August 29, 2015 14:01
Show Gist options
  • Save cbaltzer/32dde814d8b77ee3d30f to your computer and use it in GitHub Desktop.
Save cbaltzer/32dde814d8b77ee3d30f to your computer and use it in GitHub Desktop.
A convenient dispatch_after() category
/* 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
@cbaltzer
Copy link
Author

Updated to a category instead of a macro, based on this implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment