CocoaPods trunk is moving to be read-only. Read more on the blog, there are 16 months to go.

PPCustomAsyncOperation 0.1.1

PPCustomAsyncOperation 0.1.1

Maintained by istLZP.



  • By
  • pengpeng

PPCustomAsyncOperation

CI Status Version License Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

使用queue

导入头文件#import <PPCustomAsyncOperation/PPCustomOperationQueue.h>

只使用operation

导入头文件#import <PPCustomAsyncOperation/PPCustomAsyncOperation.h>

  • 正常创建queue和operation
  • 同步的任务, 直接operation.mainOperationDoBlockreturn YES;
  • 然后如果是异步的operation, 可以在operation.mainOperationDoBlock中返回NO, 并在合适的时候, 手动结束operation, 调用[operation finishOperation];
  • 具体的看Example
for (NSInteger index = 0; index < 20; index ++) {

    PPCustomAsyncOperation *operation = [[PPCustomAsyncOperation alloc] init];
    operation.identifier = [NSString stringWithFormat:@"ide_%ld", index];

    operation.mainOperationDoBlock = ^BOOL(PPCustomAsyncOperation * _Nonnull operation) {

        if (index % 2 == 0) {

            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                NSLog(@"operation: %ld", index);
                [operation finishOperation];
            });

            return NO;
        } else {
            NSLog(@"operation: %ld", index);
            return YES;
        }
    };

    [self.queue addOperation:operation];
}

Requirements

Installation

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

pod 'PPCustomAsyncOperation'

Author

pengpeng, [email protected]

License

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