GCDSwift 0.2.0

GCDSwift 0.2.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Sep 2015
SPMSupports SPM

Maintained by Mark Smith.



GCDSwift 0.2.0

  • By
  • Mark Smith

GCDSwift

GCDSwift is a Swift 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.

GCDSwift defines the same API as GCDObjC.

Usage

GCDSwift requires Swift 2.0.

For usage examples, see GCDSwiftTests.m.

GCDQueue

Queues are implemented in the GCDQueue class.

  • convenience accessors for global queues
class var mainQueue: GCDQueue { get }
class var globalQueue: GCDQueue { get }
class var highPriorityGlobalQueue: GCDQueue { get }
class var lowPriorityGlobalQueue: GCDQueue { get }
class var backgroundPriorityGlobalQueue: GCDQueue { get }
  • creating serial and concurrent queues
class func serialQueue() -> GCDQueue
class func concurrentQueue() -> GCDQueue
  • queueing blocks for asynchronous execution
func queueBlock(block: dispatch_block_t)
func queueBlock(block: dispatch_block_t, afterDelay seconds: Double)
func queueBlock(block: dispatch_block_t, inGroup group: GCDGroup)
  • queueing blocks for synchronous execution
func queueAndAwaitBlock(block: dispatch_block_t)
func queueAndAwaitBlock(block: ((Int) -> Void), iterationCount count: Int)
  • queueing barrier blocks for synchronous or asynchronous execution
func queueBarrierBlock(block: dispatch_block_t)
func queueAndAwaitBarrierBlock(block: dispatch_block_t)
  • queueing notify blocks on groups
func queueNotifyBlock(block: dispatch_block_t, inGroup group: GCDGroup)
  • suspending and resuming a queue
func suspend()
func resume()

GCDSemaphore

Semaphores are implemented in the GCDSemaphore class.

  • creating semaphores
GCDSemaphore()
GCDSemaphore(value: CLong)
  • signaling and waiting on a semaphore
func signal() -> Bool
func wait()
func wait(seconds: Double) -> Bool

GCDGroup

Groups are implemented in the GCDGroup class.

  • creating groups
GCDGroup()
  • entering and leaving a group
func enter()
func leave()
  • waiting on completion of a group
func wait()
func wait(seconds: Double) -> Bool