Skip to content

Instantly share code, notes, and snippets.

@endoze
Created July 30, 2012 15:45
Show Gist options
  • Save endoze/3207928 to your computer and use it in GitHub Desktop.
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
#import <UIKit/UIKit.h>
@interface Example : NSObject
- (void)performLongRunningTask:(SEL)taskMethod withCallback:(SEL)callbackMethod;
@end
#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