Skip to content

Instantly share code, notes, and snippets.

@taka328w
Created April 28, 2012 14:52
Show Gist options
  • Save taka328w/2519616 to your computer and use it in GitHub Desktop.
Save taka328w/2519616 to your computer and use it in GitHub Desktop.
NSObject+Extensions.m
#import "NSObject+Extensions.h"
@implementation NSObject (Extensions)
- (void)performBlock:(VoidBlock)block {
[self performSelector:@selector(executeBlock:) withObject:[block copy]];
}
- (void)performBlock:(VoidBlock)block afterDelay:(NSTimeInterval)delay {
[self performSelector:@selector(executeBlock:) withObject:[block copy] afterDelay:delay];
}
- (void)performBlockOnMainThread:(VoidBlock)block {
dispatch_async(dispatch_get_main_queue(), ^{
[self performBlock:block];
});
}
- (void)performBlockOnMainThread:(VoidBlock)block afterDelay:(NSTimeInterval)delay {
dispatch_async(dispatch_get_main_queue(), ^{
[self performBlock:block afterDelay:delay];
});
}
- (void)performBlockInBackground:(VoidBlock)block {
[self performSelectorInBackground:@selector(executeBlockInAutoReleasePool:) withObject:[block copy]];
}
- (void)executeBlock:(VoidBlock)block {
block();
[block release];
}
- (void)executeBlockInAutoReleasePool:(VoidBlock)block {
@autoreleasepool {
block();
[block release];
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment