GCDKit
GCDKit is Grand Central Dispatch simplified with Swift.
- for Swift 1.2: Use version 1.0.1
- for Swift 2.1 / 2.2: Use the master branch
Introduction
GCDKit implements the following constructs. To see how they work, jump right to the Common Usage Patterns section below.
GCDQueue
: An abstraction of thedispatch_queue_*
API.GCDQueue
s are expressed asenum
s, because we typically only need to deal with these queue types:
GCDBlock
: A struct that abstracts iOS 8's newdispatch_block_*
family of APIs.GCDGroup
: An abstraction of thedispatch_group_*
API.GCDSemaphore
: An abstraction of thedispatch_semaphore_*
API.
Common Usage Patterns
Here are some common use cases and how you can write them using GCDKit.
Creating and initializing queues
With the iOS SDK:
With GCDKit:
In addition, custom queues created with dispatch_queue_create(...)
typically target a default-priority global queue unless you use the dispatch_set_target_queue(...)
API. For example, to raise the priority level of a created queue with the current SDK:
With GCDKit, you can immediately specify the target queue on creation:
Submitting tasks to queues
With the iOS SDK:
With GCDKit you can either start a task chain from GCDBlock.async(...)
:
or directly from a specific GCDQueue
enum
value:
You can chain .notify(...)
calls as much as needed.
Launching and reporting completion of a group of tasks
With the iOS SDK:
With GCDKit you can still use the usual enter()
-leave()
pairs and you can chain async calls to the dispatch group:
Semaphores
With the iOS SDK:
With GCDKit:
Contributions
Feel free to report any issues or send suggestions!
License
GCDKit is released under an MIT license. See the LICENSE file for more information