SwiftOperation
A light-weight dependency-operation framework in Swift (inspired by the open sourced NSOperation implementation in swift-corelibs-foundation
Installation
Carthage
To integrate SwiftOperation into your Xcode project using Carthage, specify it in your Cartfile
:
github "zetasq/SwiftOperation"
Run carthage update
to build the framework. Drag the built SwiftOperation.framework
into your Xcode project.
Usage
SwiftOperation's API is very similar to NSOperation, you can add dependencies to an operation, subclass SwiftOperation
to encapsulate custom logic, etc.
let queue = SwiftOperationQueue()
let op1 = SwiftBlockOperation({ /* some work */ })
let op2 = SwiftBlockOperation({ /* some work */ })
let op3 = SwiftBlockOperation({ /* some work */ })
op3.addDependency(op1)
op3.addDependency(op2)
queue.isSuspended = true // suspend the queue first before add operations
queue.addOperations([op1, op2, op3])
queue.isSuspended = false // resume the queue to start the operations
License
SwiftOperation is released under the MIT license. See LICENSE for details.