#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
//1.创建队列
NSOperationQueue *queueA = [[NSOperationQueue alloc]init];
NSOperationQueue *queueB = [[NSOperationQueue alloc]init];
//2.封装操作
NSBlockOperation *download1 = [NSBlockOperation blockOperationWithBlock:^{
NSLog(@"download1----%@",[NSThread currentThread]);
}];
NSBlockOperation *download2 = [NSBlockOperation blockOperationWithBlock:^{
NSLog(@"download2----%@",[NSThread currentThread]);
}];
//添加操作监听
download2.completionBlock = ^{
NSLog(@"打电话给我-----%@",[NSThread currentThread]);
};
NSBlockOperation *download3 = [NSBlockOperation blockOperationWithBlock:^{
NSLog(@"download3----%@",[NSThread currentThread]);
}];
NSBlockOperation *download4 = [NSBlockOperation blockOperationWithBlock:^{
for (NSInteger i = 0; i <100; i++) {
NSLog(@"download4-%zd---%@",i,[NSThread currentThread]);
}
}];
//添加操作依赖
//注意:不能设置循环依赖
[download1 addDependency:download4];
//3.添加操作到队列
[queueA addOperation:download1];
[queueA addOperation:download2];
[queueA addOperation:download3];
[queueB addOperation:download4];
}
@end