- (void)serailQueue{
//创建出队列
GCDQueue *queue = [[GCDQueuealloc]initSerial];
//执行队列中的线程
[queueexecute:^{
NSLog(@"1");
}];
[queueexecute:^{
NSLog(@"2");
}];
[queueexecute:^{
NSLog(@"3");
}];
[queueexecute:^{
NSLog(@"4");
}];
[queueexecute:^{
NSLog(@"5");
}];
}
2015-07-11 10:34:28.641 GCDDelay[2262:174638] 1
2015-07-11 10:34:28.642 GCDDelay[2262:174638] 2
2015-07-11 10:34:28.642 GCDDelay[2262:174638] 3
2015-07-11 10:34:28.642 GCDDelay[2262:174638] 4
2015-07-11 10:34:28.643 GCDDelay[2262:174638] 5
- (void)initConcurrent{
GCDQueue *queue = [[GCDQueuealloc]initConcurrent];
//执行队列中的线程
[queueexecute:^{
NSLog(@"1");
}];
[queueexecute:^{
NSLog(@"2");
}];
[queueexecute:^{
NSLog(@"3");
}];
[queueexecute:^{
NSLog(@"4");
}];
[queueexecute:^{
NSLog(@"5");
}];
}
2015-07-11 10:38:28.849 GCDDelay[2303:178328] 3
2015-07-11 10:38:28.849 GCDDelay[2303:178334] 4
2015-07-11 10:38:28.849 GCDDelay[2303:178325] 2
2015-07-11 10:38:28.849 GCDDelay[2303:178327] 1
2015-07-11 10:38:28.850 GCDDelay[2303:178335] 5
//globalQueue 是默认级别的子线程
//一般在子线程中处理业务逻辑,主线程中更新UI
[GCDQueueexecuteInGlobalQueue:^{
//处理业务逻辑
NSURLRequest *request = [NSURLRequestrequestWithURL:[NSURLURLWithString: @"***"]];
NSData *picData =[NSURLConnectionsendSynchronousRequest:request
returningResponse:nilerror:nil];
self.image = [UIImage imageWithData:picData];
[GCDQueueexecuteInMainQueue:^{
//主线程中更新UI
self.imageView.image = self.image;
}];
}];
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/baitxaps/article/details/46839891