Skip to content

Instantly share code, notes, and snippets.

@pilky
Created December 3, 2012 22:29
Show Gist options
  • Save pilky/4198723 to your computer and use it in GitHub Desktop.
Save pilky/4198723 to your computer and use it in GitHub Desktop.
NSOperation Global Background Queue
//NSOperationQueue+GlobalBackgroundQueue.h
@interface NSOperationQueue (GlobalBackgroundQueue)
+ (instancetype)backgroundQueue;
@end
//NSOperationQueue+GlobalBackgroundQueue.m
static NSOperationQueue *backgroundQueue;
@implementation NSOperationQueue (GlobalBackgroundQueue)
+ (instancetype)backgroundQueue {
static dispatch_once_t dispatchToken;
dispatch_once(&dispatchToken, ^{
backgroundQueue = [self new];
});
return backgroundQueue;
}
@end
//Use in other code
[[NSOperationQueue backgroundQueue] addOperationWithBlock:^{
//This runs in the background
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment