Latest 1.0.4
Homepage https://github.com/orxelm/OEAsyncBlockOperation
License MIT
Platforms ios 8.0, requires ARC
Frameworks Foundation
Authors

[CocoaPods]()
Swift 3.0
Twitter

A simple NSOperation subclass to perform asynchronous operations on NSOperationQueue. In which operation isn’t finished until you invoke complete().
Mostly common for autocomplete requests when you want to perform only one async request at a time, wait for the async operation to end before exiting the queue.

Requirements

Swift 3 (For Swift 2+ please use the swift_2_2 branch)

Installation

CocoaPods

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

$ gem install cocoapods

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

source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!

pod 'OEAsyncBlockOperation'

Then, run the following command:

$ pod install

Manually

Just drag AsyncBlockOperation.swift file to your xcode project

Usage

Create Operation

self.operationQueue = OperationQueue()
self.operationQueue.maxConcurrentOperationCount = 1
...

let operation = AsyncBlockOperation.operation(withIdentifier: kBlockOperationIdentifer, queue: self.operationQueue)
weak var weakOperation = operation
operation.operationBlock = {
    RequestsManager.defaultManager.performAsyncRequestWithCompletionHandler {
        weakOperation?.complete()
    }
}

operation.cancelBlock = {
    // your cancel code here
}

self.operationQueue.addOperation(operation)
...

Cancel All Operations

AsyncBlockOperation.cancelAllAsyncBlockOperation(onQueue: self.operationQueue, withIdentifier: kBlockOperationIdentifer)
AsyncBlockOperation.cancelAllAsyncBlockOperation(onQueue: self.operationQueue)

Latest podspec

{
    "name": "OEAsyncBlockOperation",
    "version": "1.0.4",
    "summary": "A simple NSOperation subclass to perform asynchronous operations on NSOperationQueue",
    "homepage": "https://github.com/orxelm/OEAsyncBlockOperation",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Or Elmaliah": "[email protected]"
    },
    "social_media_url": "https://twitter.com/OrElm",
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/orxelm/OEAsyncBlockOperation.git",
        "tag": "1.0.4"
    },
    "source_files": "AsyncBlockOperation/Source/AsyncBlockOperation.swift",
    "requires_arc": true,
    "frameworks": "Foundation",
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This