Created
April 28, 2012 14:52
-
-
Save taka328w/2519616 to your computer and use it in GitHub Desktop.
NSObject+Extensions.m
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
#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