用于支持异步块的 NSOperation 子类。
Swift
import AsyncBlockOperation
let queue = NSOperationQueue()
/// Method 1. Using `AsyncBlockOperation` object
let operation = AsyncBlockOperation { op in
op.complete() // call this method when async task finished
}
queue.addOperation(operation)
/// Method 2. Using `NSOperationQueue` method
queue.addOperationWithAsyncBlock { op in
op.complete()
}
Objective-C
#import <AsyncBlockOperation/AsyncBlockOperation.h>
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
// Method 1. Using `AsyncBlockOperation` object
AsyncBlockOperation *operation = [AsyncBlockOperation blockOperationWithBlock:^(AsyncBlockOperation *op) {
[op complete]; // call this method when async task finished
}];
[queue addOperation:operation];
// Method 2. Using `NSOperationQueue` method
[queue addOperationWithAsyncBlock:^(AsyncBlockOperation *op) {
[op complete];
}];
我建议您使用 CocoaPods,它是 Cocoa 的依赖项管理器。
Podfile
pod 'AsyncBlockOperation', '~> 1.0'
AsyncBlockOperation 使用 MIT 许可证。请参阅 LICENSE 文件获取更多信息。