TestsTested | ✓ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Jun 2016 |
Maintained by Mark Smith.
GCDObjC is an Objective-C wrapper for the most commonly used features of Grand Central Dispatch. It has four main aims:
A Swift port is at GCDSwift.
GCDObjC requires ARC and iOS 6.0. (Prior to 6.0, dispatch objects were not considered Objective-C objects, and therefore required manual memory management.)
GCDObjC.h is the only header file that needs to be imported.
For usage examples, see GCDObjCTests.m.
Install via CocoaPods:
pod "GCDObjC"
Queues are implemented in the GCDQueue class.
+ (GCDQueue *)mainQueue;
+ (GCDQueue *)globalQueue;
+ (GCDQueue *)highPriorityGlobalQueue;
+ (GCDQueue *)lowPriorityGlobalQueue;
+ (GCDQueue *)backgroundPriorityGlobalQueue;
+ (BOOL)isMainQueue;
- (instancetype)initSerial;
- (instancetype)initConcurrent;
- (void)queueBlock:(dispatch_block_t)block;
- (void)queueBlock:(dispatch_block_t)block afterDelay:(double)seconds;
- (void)queueBlock:(dispatch_block_t)block inGroup:(GCDGroup *)group;
- (void)queueAndAwaitBlock:(dispatch_block_t)block;
- (void)queueAndAwaitBlock:(void (^)(size_t))block iterationCount:(size_t)count;
- (void)queueBarrierBlock:(dispatch_block_t)block;
- (void)queueAndAwaitBarrierBlock:(dispatch_block_t)block;
- (void)queueNotifyBlock:(dispatch_block_t)block inGroup:(GCDGroup *)group;
- (void)suspend;
- (void)resume;
- (void *)contextForKey:(const void *)key;
- (void)setContext:(void *)context forKey:(const void *)key;
Semaphores are implemented in the GCDSemaphore class.
- (instancetype)init;
- (instancetype)initWithValue:(long)value;
- (BOOL)signal;
- (void)wait;
- (BOOL)wait:(double)seconds;
Groups are implemented in the GCDGroup class.
- (instancetype)init;
- (void)enter;
- (void)leave;
- (void)wait;
- (BOOL)wait:(double)seconds;
Two macros are provided for wrapping dispatch_once() calls.
for (int i = 0; i < 10; ++i) {
GCDExecOnce(^{ NSLog(@"This will only be logged once."); });
}
+ (instancetype)sharedInstance {
GCDSharedInstance(^{ return [self new]; });
}
The block supplied to GCDSharedInstance() must return an instance of the desired class.