Created
December 3, 2012 22:29
-
-
Save pilky/4198723 to your computer and use it in GitHub Desktop.
NSOperation Global Background Queue
This file contains hidden or 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
//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