Latest | 0.1.6 |
---|---|
Homepage | https://github.com/danchoys/DKCompoundOperation |
License | MIT |
Platforms | ios 7.0, requires ARC |
Authors |
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.
Latest podspec
{ "name": "DKCompoundOperation", "version": "0.1.6", "summary": "Compound operation for use with NSOperationQueue", "homepage": "https://github.com/danchoys/DKCompoundOperation", "license": "MIT", "authors": { "Daniil Konoplev": "[email protected]" }, "source": { "git": "https://github.com/danchoys/DKCompoundOperation.git", "tag": "0.1.6" }, "platforms": { "ios": "7.0" }, "requires_arc": true, "source_files": "Pod/Classes/**/*" }
Sat, 27 Feb 2016 04:24:03 +0000