Latest 0.3.0
Homepage https://github.com/siuying/SwiftyDispatch
License MIT
Platforms ios 8.0, osx 10.10, requires ARC
Authors

A lightweight GCD wrapper for Swift. Mostly copied from MacRuby’s Dispatch module.

Version
License
Platform

Usage

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

Queue

Create queues

// Create a serial queue
let queue = Queue("Serial", .Serial)

// Create a concurrent queue
let queue = Queue("Concurrent", .Concurrent)

// It is serial by default
let queue = Queue("Concurrent")

// Get main queue
let queue = Queue.main()

// Get global queue via QOS
let queue = Queue.concurrent(.UserInteractive)

// Get global queue via priority
let queue = Queue.concurrent(priority: .Background)

Run blocks

// asynchronously
queue.async {
  data = true
}

// synchronously
queue.sync {
  data = true
}

Apply

queue.apply(10) {
  // some concurrent task
}

After

queue.apply(0.3) {
  // run after 0.3 seconds
}

Semaphore

Semaphore provides an efficient mechanism to synchronizes threads via a combination of waiting and signaling.

This is especially useful for controlling access to limited resources.

let queue = Queue("sample")
let semaphore = Semaphore(0)
queue.after(1.0) {
  print "Hello"
  semaphore.signal
}
semaphore.wait // -> true

Requirements

  • Swift 2.0 (Xcode 7)

Installation

CocoaPods

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

pod "SwiftyDispatch"

Carthage

You can use Carthage to install SwiftyDispatch by adding it to your Cartfile:

github "siuying/SwiftyDispatch"

Manually

To use this library in your project manually, just drag all swift files under Classes to the project tree.

TODO?

  • [x] Queue
  • [x] Async/Sync
  • [x] Apply
  • [x] After
  • [x] Semaphore
  • [ ] Barrier
  • [ ] Group
  • [ ] Source
  • [ ] Block class

Author

Francis Chong, [email protected]

License

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

Latest podspec

{
    "name": "SwiftyDispatch",
    "version": "0.3.0",
    "summary": "A lightweight GCD wrapper for Swift.",
    "homepage": "https://github.com/siuying/SwiftyDispatch",
    "license": "MIT",
    "authors": {
        "Francis Chong": "[email protected]"
    },
    "source": {
        "git": "https://github.com/siuying/SwiftyDispatch.git",
        "tag": "0.3.0"
    },
    "social_media_url": "https://twitter.com/siuying",
    "platforms": {
        "ios": "8.0",
        "osx": "10.10"
    },
    "requires_arc": true,
    "source_files": "Classes/**/*.swift"
}

Pin It on Pinterest

Share This