Skip to content

EasySwift/gcdswift

 
 

Repository files navigation

GCDSwift

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.

Usage

GCDSwift requires Swift 2.0.

For usage examples, see GCDSwiftTests.swift.

Install via CocoaPods:

pod "GCDSwift"

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: Int)
  • 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

About

Swift wrapper for Grand Central Dispatch

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 93.2%
  • Ruby 6.8%