Giter Club home page Giter Club logo

cooperation's Introduction

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.

cooperation's People

Contributors

brain89 avatar constzinovyev avatar etolstoy avatar novixon avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.