Created
July 30, 2012 15:45
-
-
Save endoze/3207928 to your computer and use it in GitHub Desktop.
GCD convenience method for a long running task and a callback when it's done
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 <UIKit/UIKit.h> | |
@interface Example : NSObject | |
- (void)performLongRunningTask:(SEL)taskMethod withCallback:(SEL)callbackMethod; | |
@end |
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 "Example.h" | |
@implementation | |
- (void)performLongRunningTask:(SEL)taskMethod withCallback:(SEL)callbackMethod | |
{ | |
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^() | |
{ | |
[self performSelector:taskMethod]; | |
dispatch_async(dispatch_get_main_queue(), ^() | |
{ | |
[self performSelector:callbackMethod]; | |
}); | |
}); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment