异步下载
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{//扔给另外的cpu处理
NSLog(@"downData");dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"refresUI");
});
});
队列下载 提交给系统 并发 但是仍然可以有优先级,但是也没多大用途.
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_group_t group = dispatch_group_create();
dispatch_group_async(group, queue, ^{
for (int i =0; i<1; i++)
{
NSLog(@"dosomething");
}
});
dispatch_group_notify(group, dispatch_get_main_queue(), ^{
NSLog(@"updateUi");
});
dispatch_release(group);
//dispatch_group 可以向 dispathc_queue 提交代码块 。dispatch_group 可以转移执行 dispathc_queue
///有点象 队列了
dispatch_queue_t testQueue =dispatch_queue_create("com.hu.qinghe",DISPATCH_QUEUE_SERIAL);
dispatch_async(testQueue, ^{
for (int i =0; i<100; i++) {
NSLog(@"i------;%d",i);
}
});
dispatch_async(testQueue, ^{
for (int i =0; i<100; i++) {
NSLog(@"j=====;%d",i);
}
});
NSLog(@"backGround");
dispatch_release(testQueue);