Created
September 26, 2014 21:02
-
-
Save mpvosseller/4adac1e421d5c5e44f8e to your computer and use it in GitHub Desktop.
Block based replacement for -[NSObject performSelector:withObject:afterDelay:]
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
// Block based replacement for | |
// -[NSObject performSelector:withObject:afterDelay:] | |
// because I can never remember how to do it with the dispatch_after & dispatch_time functions | |
// | |
// NSObject+MPV.h | |
// iFoodler | |
// | |
// Created by Michael Vosseller on 9/26/14. | |
// Copyright (c) 2014 MPV Software, LLC. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
@interface NSObject (MPV) | |
- (void) mpv_afterDelay:(NSTimeInterval)delaySeconds performBlock:(void (^)(void))block; | |
@end | |
// | |
// NSObject+MPV.m | |
// iFoodler | |
// | |
// Created by Michael Vosseller on 9/26/14. | |
// Copyright (c) 2014 MPV Software, LLC. All rights reserved. | |
// | |
#import "NSObject+MPV.h" | |
@implementation NSObject (MPV) | |
- (void) mpv_afterDelay:(NSTimeInterval)delaySeconds performBlock:(void (^)(void))block { | |
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delaySeconds * NSEC_PER_SEC)), dispatch_get_main_queue(), block); | |
} | |
@end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment