Coder Social home page Coder Social logo

dkcompoundoperation's Introduction

DKCompoundOperation

Version License Platform

This easy-to-use and lightweight component allows to organize operations in sequences, providing a single interface for progress and completion tracking. It also makes possible the cancellation of the whole compound operation through the NSProgress instance.

Usage

The following code shows how to make a three-step operation of exporting video from ALAssetsLibrary, uploading the result to the remote server and performing some necessary cleanup. It assumes that there are two classed: ExportVidoOperation and UploadVideoOperation, inheriting from DKOperation.

import <DKCompoundOperation/DKCompoundOperation.h>

static NSInteger const kExportOperationProgressFraction = 30;
static NSInteger const kUploadOperationProgressFraction = 65;
static NSInteger const kCleanupOperationProgressFraction = 5;

<...>

@property (nonatomic, strong) NSOperationQueue *queue;
@property (nonatomic, weak) NSProgress *progress;

<...>

DKCompoundOperation *operation = [[DKCompoundOperation alloc] init];
[operation addOperationCreatedUsingBlock:^DKOperation *{
    return [ExportVideoOperation operationWithVideoAssetURL:assetURL];
} progressFraction:kExportOperationProgressFraction];
[operation addOperationCreatedUsingBlock:^DKOperation *{
    return [UploadVideoOperation operation];
} progressFraction:kUploadOperationProgressFraction];
[operation addOperationWithOperationBlock:^(DKOperation *operation) {
    operation.progress.totalUnitCount = 150;
    // Perform some cleanup operations 
    // updating operation.progress
    operation.completeOperation(YES, nil);
} progressFraction:kCleanupOperationProgressFraction];
operation.completionBlock = ^(BOOL success, NSError *error) {
    if (error) {
        NSLog(@"Error occured: %@", error);
        return;
    }
    self.completedLabel.hidden = NO;
};
self.progress = operation.progress;
[self.queue addCompoundOperation:operation];

You may track changes to the progress object using KVO. For more information, visit the NSProgress Class Reference and Key-Value Observing Guide.

Installation

DKCompoundOperation is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "DKCompoundOperation"

Author

Daniil Konoplev, [email protected]

License

DKCompoundOperation is available under the MIT license. See the LICENSE file for more info.

dkcompoundoperation's People

Contributors

danchoys avatar

Stargazers

Alex Shevchenko avatar Nikita Ivanchykov avatar  avatar Indrajit Chakrabarty avatar

Watchers

James Cloos 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.