reference to : http://www.jianshu.com/p/4c983388dca6
估计现在好多人在为这一块头疼,所以先来点干货。
1
2
3
4
5
6
7
8
|
//最常用模板 //全局队列异步执行 DispatchQueue . global (). async {
//耗时操作
DispatchQueue . main . async {
//回到主线程
}
} |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
//创建新队列 DispatchQueue ( label : "newQueue" , attributes : . concurrent , target : nil ). async {
//并行队列异步执行
} //创建新队列 DispatchQueue ( label : "newQueue" , attributes : . concurrent , target : nil ). sync {
//并行队列同步执行
} //创建新队列 DispatchQueue ( label : "newQueue" ). async {
//串行队列异步执行
} //创建新队列 DispatchQueue ( label : "newQueue" ). sync {
//串行队列同步执行
} let delay : TimeInterval = 3
DispatchQueue . main . asyncAfter ( deadline : DispatchTime . now () + delay ) {
//3秒后在主线程执行
} |
dispatch_block_t
在swift3.0已经没了 dispatch_block_t
等价于() -> void
dispatch_queue_t
等价于DispatchQueue
自己看语法特点
大致这么多差不多就能解决大部分问题了,其它自己根据GCD自己对号入座。