https://github.com/strongself/cooperation
Your service implementation is a cooperation of your Core-components.
https://github.com/strongself/cooperation
Last synced: 10 months ago
JSON representation
Your service implementation is a cooperation of your Core-components.
- Host: GitHub
- URL: https://github.com/strongself/cooperation
- Owner: strongself
- License: mit
- Created: 2016-11-05T19:16:35.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-08-21T09:25:27.000Z (almost 9 years ago)
- Last Synced: 2025-08-23T22:11:44.018Z (10 months ago)
- Language: Objective-C
- Size: 172 KB
- Stars: 55
- Watchers: 28
- Forks: 6
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Your service implementation is a cooperation of your core components




**COOperation** is a component for organizing and structuring the code of your service layer with the help of *NSOperation*.
| | Key Features|
|---------|---------------|
|🏰 | Design beautiful and reusable business logic|
|🙏 | Follow the SOLID principles out of the box|
|🍏 | Use the *Compound Operations* concept introduced by Apple at WWDC 2015 ([Advanced NSOperations](https://developer.apple.com/videos/play/wwdc2015/226/))
|☑ | Write unit and integration tests easily|
**COOperation** is written in Objective-C with full Swift interop support. By the way, we are working on a Swift version!
## Installation
### Cocoapods
The preferred installation method for `COOperation` is with [CocoaPods](http://cocoapods.org). Simply add the following to your Podfile:
```ruby
# Latest release of COOperation
pod 'COOperation'
```
## Usage
### Creating your "Chainable Operation"
```swift
import Foundation
import CompoundOperations
/// Chainable operation that performs network request
class NetworkRequestChainableOperation: ChainableOperationBase {
/// Network client (Core-component)
private let networkClient: NetworkClient
init(networkClient: NetworkClient) {
self.networkClient = networkClient
super.init()
}
// MARK: Executing
override func inputDataClass() -> AnyClass? {
return NSURLRequest.self
}
override func processInputData(inputData: AnyObject?,
completionBlock: ChainableOperationBaseOutputDataBlock) {
let inputRequest = inputData as! NSURLRequest
networkClient.performRequest(inputRequest) { (data, error) in
completionBlock(data, error)
}
}
}
```
### Creating your "Compound Operation"
```swift
func obtainDataCompoundOperation(withResultBlock resultBlock: CompoundOperationResultBlock?) -> CompoundOperation {
let networkRequestOperation = NetworkRequestChainableOperation(networkClient: NetworkClientImplementation())
let deserializationOperation = DeserializationChainableOperation(deserializer: JSONDeserializer)
let chainableOperations = [
networkRequestOperation,
deserializationOperation
]
let operation = CompoundOperation.defaultCompoundOperation()
operation.configureWithChainableOperations(chainableOperations,
resultBlock: resultBlock)
return operation
}
```
### Using your "Compound Operation" in your services
```swift
let compoundOperation = obtainDataCompoundOperation { (data, error) in
// Process the result
}
queue.addOperation(compoundOperation) // OR compoundOperation.start()
```
### Author
- Gleb Novik, Egor Tolstoy and the rest of [Rambler.iOS team](https://github.com/orgs/rambler-digital-solutions/teams/ios-team).
### License
MIT
### Thanks
[Sergey Simanov](https://dribbble.com/SlmacH) - impressive logo design.