Giter VIP home page Giter VIP logo

gcdobjc's Introduction

GCDObjC

GCDObjC is an Objective-C wrapper for the most commonly used features of Grand Central Dispatch. It has four main aims:

  • Organize the flat C API into appropriate classes.
  • Use intention-revealing names to distinguish between synchronous and asynchronous functions.
  • Use more convenient arguments such as time intervals.
  • Add convenience methods.

Usage

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.

GCDQueue

Queues are implemented in the GCDQueue class.

  • convenience accessors for global queues
+ (GCDQueue *)mainQueue;
+ (GCDQueue *)globalQueue;
+ (GCDQueue *)highPriorityGlobalQueue;
+ (GCDQueue *)lowPriorityGlobalQueue;
+ (GCDQueue *)backgroundPriorityGlobalQueue;
  • creating serial and concurrent queues
- (instancetype)initSerial;
- (instancetype)initConcurrent;
  • queueing blocks for asynchronous execution
- (void)queueBlock:(dispatch_block_t)block;
- (void)queueBlock:(dispatch_block_t)block afterDelay:(double)seconds;
- (void)queueBlock:(dispatch_block_t)block inGroup:(GCDGroup *)group;
  • queueing blocks for synchronous execution
- (void)queueAndAwaitBlock:(dispatch_block_t)block;
- (void)queueAndAwaitBlock:(void (^)(size_t))block iterationCount:(size_t)count;
  • queueing barrier blocks for synchronous or asynchronous execution
- (void)queueBarrierBlock:(dispatch_block_t)block;
- (void)queueAndAwaitBarrierBlock:(dispatch_block_t)block;
  • queueing notify blocks on groups
- (void)queueNotifyBlock:(dispatch_block_t)block inGroup:(GCDGroup *)group;
  • suspending and resuming a queue
- (void)suspend;
- (void)resume;

GCDSemaphore

Semaphores are implemented in the GCDSemaphore class.

  • creating semaphores
- (instancetype)init;
- (instancetype)initWithValue:(long)value;
  • signaling and waiting on a semaphore
- (BOOL)signal;
- (void)wait;
- (BOOL)wait:(double)seconds;

GCDGroup

Groups are implemented in the GCDGroup class.

  • creating groups
- (instancetype)init;
  • entering and leaving a group
- (void)enter;
- (void)leave;
  • waiting on completion of a group
- (void)wait;
- (BOOL)wait:(double)seconds;

Macros

Two macros are provided for wrapping dispatch_once() calls.

  • executing a block only once: GCDExecOnce(block)
for (int i = 0; i < 10; ++i) {
    GCDExecOnce(^{ NSLog(@"This will only be logged once."); });
}
  • creating a singleton instance of a class: GCDSharedInstance(block)
+ (instancetype)sharedInstance {
  GCDSharedInstance(^{ return [[self class] new]; });
}

The block supplied to GCDSharedInstance() must return an instance of the desired class.

gcdobjc's People

Contributors

mjmsmith avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.