GCDSwift is no longer supported. For iOS 10+, use the Dispatch framework.
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.
GCDSwift requires Swift 2.0.
For usage examples, see GCDSwiftTests.swift.
Install via CocoaPods:
pod "GCDSwift"
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()
Semaphores are implemented in the GCDSemaphore class.
- creating semaphores
GCDSemaphore()
GCDSemaphore(value: Int)
- signaling and waiting on a semaphore
func signal() -> Bool
func wait()
func wait(seconds: Double) -> Bool
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