A light-weight dependency-operation framework in Swift (inspired by the open sourced NSOperation implementation in swift-corelibs-foundation
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.
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
SwiftOperation is released under the MIT license. See LICENSE for details.