Latest 1.0
Homepage https://github.com/zuccoi/AsyncOperation
License MIT
Platforms ios 11.0.1

AsyncOperation

Generic subclass of Operation to get result asynchronously.

Usage

// Define success type
struct MyOperationSuccess {
    // …
}

// Make subclass of AsyncOperation whose success type is `MyOperationSuccess`
class MyOperation: AsyncOperation<MyOperationSuccess> {
    // …

    override func didStartExecuting() {
        // Do something…
        // When completed, call `self.complete()` with `MyOperationSuccess` instance
        // When failed, call `self.fail()` with `Error`
    }
}

// Make `MyOperation` instance
let op = MyOperation()
// Start the operation with `didEndBlock` which is called when the operation is cancelled or finished. Alternatively, you can add the operation into `OperationQueue`.
op.start {
    do {
        let result = try op.getResult() // Type of 'result' is `MyOperationSuccess`
        // Do something with result…
    } catch AsyncOperationError.cancelled(let canceller) {
        // Handle cancellation…
    } catch {
        // Handle other errors…
    }
}

More

AsyncBlockOperation is provided to make an operation with block.

Requirements

  • Swift 5.0 or later
  • iOS 11.0.1 or later
  • Mac OS T.B.D.
  • watchOS T.B.D.
  • tvOS T.B.D.

Installation

Carthage

Not supported yet.

CocoaPods

  • Insert pod 'ZUAsyncOperation' to your Podfile.
  • Run pod install.

Manually

Copy files under Source folder to your project (e.g. AsyncOperation.swift).

License

MIT.

Latest podspec

{
    "name": "ZUAsyncOperation",
    "version": "1.0",
    "summary": "Generic subclass of Operation to get result asynchronously.",
    "description": "AsyncOperation is a generic subclass of Operation to get Swift.Result asynchronously.",
    "homepage": "https://github.com/zuccoi/AsyncOperation",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": "zuccoi",
    "social_media_url": "https://twitter.com/zuccoi",
    "platforms": {
        "ios": "11.0.1"
    },
    "source_files": "AsyncOperation/AsyncOperation/Source/*.{swift}",
    "source": {
        "git": "https://github.com/zuccoi/AsyncOperation.git",
        "tag": "1.0"
    },
    "swift_versions": "5.0",
    "swift_version": "5.0"
}

Pin It on Pinterest

Share This