Last active
December 12, 2015 12:19
-
-
Save fmundaca/4771335 to your computer and use it in GitHub Desktop.
Ejecutar un bloque de código con un pequeño delay.
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+PWObject.h | |
#import <Foundation/Foundation.h> | |
@interface NSObject (PWObject) | |
- (void)performBlock:(void (^)(void))block afterDelay:(NSTimeInterval)delay; | |
@end | |
/* NSObject+PWObject.m */ | |
@implementation NSObject (PWObject) | |
- (void)performBlock:(void (^)(void))block afterDelay:(NSTimeInterval)delay | |
{ | |
int64_t delta = (int64_t)(1.0e9 * delay); | |
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delta), dispatch_get_main_queue(), block); | |
} | |
@end | |
// Para ejecutarlo desde cualquier clase. | |
#import "NSObject+PWObject.h" | |
[self performBlock:^{ | |
NSLog("bloque ejecutado"); | |
} afterDelay:1.0]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment