Latest 0.7.0
License MIT
Platforms ios 9.0

[![CI Status]( Whetstone/Dispatch3.svg?style=flat)]( Whetstone/Dispatch3)

Dispatch3 is a wrapper around the iOS9 Dispatch framework providing the same syntax and functionality as the new Dispatch framework in iOS10.


I was watching the WWDC session on GCD in Swift 3 and wanted to start using the new and much cleaner syntax without having to wait for Xcode 8 to be released. So I decided to see if I could replicate a subset of its functionality in XCode 7.3.

What’s done?

So far, it only contains the basics – but you can still do a lot with those! Here’s what you can do:

import Dispatch3

class DispatchStuff
    let sq = DispatchQueue("com.example.some_queue", attr: .serial)
    let cq = DispatchQueue("com.example.another_queue", attr: .concurrent)

    let x = 5

    func foo() throws
        // You can return from a sync closure! And you don't have to
        // reference self (closure is @noescape)

        let y = sq.sync { return x }

        // You can also throw from a sync closure!
        try sq.sync { throw SomeException }

        // dispatch_after is much simpler
        sq.after(.now() + 5) { print "Isn't that much easier?" }
        sq.after(.now() + .milliseconds(500)) { print "No conversions necessary" }

        // Dispatch groups!
        let g = DispatchGroup()
        cq.async(group: g) { /* Do the thing */ }
        cq.async(group: g) { /* Do the other thing */ }
        someObject.customThing(completion: { g.leave() })
        group.notify { /* Do when thing, other thing, and custom thing are done */ }

        // Barrier blocks!
        for i in 0..<10
            cq.async { /* Do the thing */ }

        cq.async(flags: .barrier) { /* called after cq is drained */ }

        // Dispatch on the main queue
        DispatchQueue.main.async { /* update the UI */ }

        // Dispatch on a global queue .qosBackground).async { ... }

    func bar()
        // Preconditions!
        print("I feel safer already")

Next steps

This project will never reach 100% compatibility, and most likely won’t even get close. After all, it’s got a limited shelf-life – becoming obsolete as soon as Xcode 8 is released. With that said, I will be adding more features as I need them. Feel free to contribute others.


To run the example project, clone the repo, and run pod install from the Example directory first.



Dispatch3 is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "Dispatch3"


David Whetstone, [email protected]


Dispatch3 is available under the MIT license. See the LICENSE file for more info.

Latest podspec

    "name": "Dispatch3",
    "version": "0.7.0",
    "summary": "iOS 10 workalike Dispatch framework for iOS 9",
    "description": "Dispatch3 is a wrapper around the iOS9 Dispatch framework providing the same syntax and functionality as the new Dispatch framework in iOS10. It provides features like the ability to return values and throw exceptions from sync closures, dispatchPrecondition(), and the much simpler replacement for dispatch_after().",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": {
        "David Whetstone": "[email protected]"
    "source": {
        "git": "",
        "tag": "0.7.0"
    "social_media_url": "",
    "platforms": {
        "ios": "9.0"
    "source_files": "Dispatch3/Classes/**/*"

Pin It on Pinterest

Share This