PPCustomAsyncOperation 0.1.1

PPCustomAsyncOperation 0.1.1

istLZP维护。



  • pengpeng

PPCustomAsyncOperation

CI Status Version License Platform

示例

要运行示例项目,首先克隆仓库,并在 Example 目录中运行 pod install

使用queue

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

只使用 operation

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

  • 正常创建queue和operation
  • 同步的任务,直接在operation.mainOperationDoBlock中返回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];
}

需求

安装

PPCustomAsyncOperation可通过CocoaPods获取。安装时,只需将以下行添加到您的Podfile中

pod 'PPCustomAsyncOperation'

作者

pengpeng, [email protected]

许可证

PPCustomAsyncOperation在MIT许可证下可用。有关更多信息,请参阅LICENSE文件。