Skip to content

Instantly share code, notes, and snippets.

@fmundaca
Last active December 12, 2015 12:19
Show Gist options
  • Save fmundaca/4771335 to your computer and use it in GitHub Desktop.
Save fmundaca/4771335 to your computer and use it in GitHub Desktop.
Ejecutar un bloque de código con un pequeño delay.
// 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