CocoaPods trunk is moving to be read-only. Read more on the blog, there are 13 months to go.
| TestsTested | ✓ |
| LangLanguage | SwiftSwift |
| License | MIT |
| ReleasedLast Release | Feb 2017 |
| SwiftSwift Version | 3.0-GM-CANDIDATE |
| SPMSupports SPM | ✗ |
Maintained by Jorge Orjuela.
A Swift framework inspired by WWDC 2015 Advanced NSOperations session.
Operation is an Foundation.Operation subclass. It is an abstract class which should be subclassed.
import OperationKit
class FooOperation: Operation {
override func execute() {
print("running")
finish()
}
}
let operationQueue = OperationQueue()
let fooOperation = FooOperation()
operationQueue.addOperation(fooOperation)Observers are attached to an Operation. They receive callbacks when operation events occur.:
operation.addObserver(BlockObserver { operation, _ in
print("finished")
})OperationKit also provides TimeoutObserver and NetworkObserver.
Conditions are attached to an Operation. Before an operation is ready to execute it will asynchronously evaluate all of its conditions. If any condition fails, the operation finishes with an error instead of executing. For example:
let urlRequestOperation = URLRequestOperation(request: request)
urlRequestOperation.addCondition(ReachabilityCondition(host: request.url!))import OperationKit
let operationQueue = OperationKit.OperationQueue()
let dataRequestOperation = DataRequestOperation(request: request)
operationQueue.addOperation(operationQueue)Handling the Response of a DataRequest made in OpertationKit is easy.
dataRequestOperation.responseJSON { result in
switch result {
case let .success(responseJSON):
print(responseJSON)
case let .failure(_error):
print("error")
}
}