Latest 2.1.2
Homepage https://github.com/jorjuela33/OperationKit
License MIT
Platforms ios 8.0
Authors

A Swift framework inspired by WWDC 2015 Advanced NSOperations session.

Requirements

  • iOS 8.0+
  • Xcode 8.1+
  • Swift 3.0+

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate OperationKit into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'OperationKit', '~> 2.1'
end

Then, run the following command:

$ pod install

Usage

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

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

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!))

Making a Request

import OperationKit

let operationQueue = OperationKit.OperationQueue()
let dataRequestOperation = DataRequestOperation(request: request)
operationQueue.addOperation(operationQueue)

Response Handling

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")
    }
}

Latest podspec

{
    "name": "OperationKit",
    "platforms": {
        "ios": "8.0"
    },
    "version": "2.1.2",
    "summary": "OperationKit is a small group of classes.",
    "description": "Couple of operation class that helps in the development",
    "homepage": "https://github.com/jorjuela33/OperationKit",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Jorge Mario Orjuela Gutierrez": "[email protected]"
    },
    "source": {
        "git": "https://github.com/jorjuela33/OperationKit.git",
        "tag": "2.1.2"
    },
    "source_files": "OperationKit/**/*.{swift}",
    "pushed_with_swift_version": "3.0-GM-CANDIDATE"
}

Pin It on Pinterest

Share This