Latest 0.0.3
Homepage https://github.com/strongself/COOperation
License MIT
Platforms ios 7.0, requires ARC
Authors ,

Your service implementation is a cooperation of your core components

Version
License
Test Coverage
Status

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)
☑ | 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. Simply add the following to your Podfile:

# Latest release of COOperation
pod 'COOperation'

Usage

Creating your "Chainable Operation"

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"

    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

    let compoundOperation = obtainDataCompoundOperation { (data, error) in
        // Process the result
    }

    queue.addOperation(compoundOperation) // OR compoundOperation.start()

Author

License

MIT

Thanks

Sergey Simanov – impressive logo design.

Latest podspec

{
    "name": "COOperation",
    "version": "0.0.3",
    "summary": "Library for working with compound operations",
    "license": "MIT",
    "authors": {
        "Gleb Novik": "[email protected]",
        "Egor Tolstoy": "[email protected]"
    },
    "homepage": "https://github.com/strongself/COOperation",
    "source": {
        "git": "https://github.com/strongself/COOperation.git",
        "tag": "0.0.3"
    },
    "source_files": "Source/**/*.{h,m}",
    "platforms": {
        "ios": "7.0"
    },
    "requires_arc": true
}

Pin It on Pinterest

Share This