08-dispatch_apply
1 dispatch_apply
dispatch_apply 是按照指定的次數將指定的block 新增到指定的queue當中去。
可以用於快速的迭代
// 獲取全域性併發佇列
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
// 迭代陣列
NSLog(@"begin");
NSArray *arr = @[@"apple",@"orange",@"watermelon",@"banana"];
dispatch_apply(arr.count, queue, ^(size_t idx) {
NSLog(@"idx-%@",arr[idx]);
});
NSLog(@"end");
// 列印結果
2018-12-13 11:36:00.915525+0800 Dispatch_apply_demo[6696:100664] begin
2018-12-13 11:36:00.915688+0800 Dispatch_apply_demo[6696:100664] idx-apple
2018-12-13 11:36:00.915696+0800 Dispatch_apply_demo[6696:100700] idx-orange
2018-12-13 11:36:00.915712+0800 Dispatch_apply_demo[6696:100695] idx-watermelon
2018-12-13 11:36:00.915717+0800 Dispatch_apply_demo[6696:100698] idx-banana
2018-12-13 11:36:00.915878+0800 Dispatch_apply_demo[6696:100664] end
2 dispatch_suspend 掛起指定的queue
掛起的時候對已經執行的處理沒有影響