标签:
- (id)initWithTarget:(id)target selector:(SEL)sel object:(id)arg;
- (void)start;
一旦执行操作,就会调用target的sel方法
+ (id)blockOperationWithBlock:(void (^)(void))block;
- (void)addExecutionBlock:(void (^)(void))block;
注意:只要NSBlockOperation封装的操作数 > 1,就会异步执行操作
类比GCD:此时(任务)operation相当于GCD中的block,队列queue相当于GCD中的队列.队列是什么类型取决于任务放在哪个线程执行,主线程就是主队列,子线程就是全局并发对列
NSOperationQueue
- (void)addOperation:(NSOperation *)op;
- (void)addOperationWithBlock:(void (^)(void))block;
最大并发数
- (NSInteger)maxConcurrentOperationCount;
- (void)setMaxConcurrentOperationCount:(NSInteger)cnt;
队列的取消、暂停、恢复
- (void)cancelAllOperations;
提示:也可以调用NSOperation的- (void)cancel方法取消单个操作
- (void)setSuspended:(BOOL)b; // YES代表暂停队列,NO代表恢复队列
- (BOOL)isSuspended;
操作优先级
- (NSOperationQueuePriority)queuePriority;
- (void)setQueuePriority:(NSOperationQueuePriority)p;
- (void (^)(void))completionBlock;
- (void)setCompletionBlock:(void (^)(void))block;
操作依赖
[operationB addDependency:operationA]; // 操作B依赖于操作A
NSOperation & NSOperationQueue
标签:
原文地址:http://www.cnblogs.com/CDSmallCat/p/4965082.html