Swift 3 在GCD的语法上改变了很多,更加贴近了swift的语法,而且关于队列的优先级也改变了不少。
原先的GCD只有四个优先级,high,default,low,background
然而现在的GCD有六个优先级,background,utility,default,userInitiated,userInteractive,unspecified
经过试验,得出了几个结论,
userInteractive的优先级最高,相当于high
background的优先级最低,相当于原来的background
default的优先级高于unspecified,userInitiated,utility
unspecified的优先级高于userInitiated,utility
userInitiated的优先级高于utility
userInteractive>default>unspecified>userInitiated>utility>background
另附实验代码,若有不正确的地方欢迎指正
for i in 1...10 { DispatchQueue.global(qos: DispatchQoS.QoSClass.default).async { NSLog("DispatchQoS.QoSClass.default,%d",i) } DispatchQueue.global(qos: DispatchQoS.QoSClass.background).async { NSLog("DispatchQoS.QoSClass.background,i) } DispatchQueue.global(qos: DispatchQoS.QoSClass.unspecified).async { NSLog("DispatchQoS.QoSClass.unspecified,i) } DispatchQueue.global(qos: DispatchQoS.QoSClass.userInitiated).async { NSLog("DispatchQoS.QoSClass.userInitiated,i) } DispatchQueue.global(qos: DispatchQoS.QoSClass.userInteractive).async { NSLog("DispatchQoS.QoSClass.userInteractive,i) } DispatchQueue.global(qos: DispatchQoS.QoSClass.utility).async { NSLog("DispatchQoS.QoSClass.utility,i) } }
试验数据:
2016-11-15 11:46:12.927070 GraphicsContext[2099:635166] DispatchQoS.QoSClass.userInteractive,1 2016-11-15 11:46:12.927363 GraphicsContext[2099:635166] DispatchQoS.QoSClass.userInteractive,2 2016-11-15 11:46:12.927407 GraphicsContext[2099:635171] DispatchQoS.QoSClass.userInteractive,3 2016-11-15 11:46:12.927490 GraphicsContext[2099:635166] DispatchQoS.QoSClass.userInteractive,4 2016-11-15 11:46:12.927674 GraphicsContext[2099:635166] DispatchQoS.QoSClass.userInteractive,5 2016-11-15 11:46:12.927780 GraphicsContext[2099:635166] DispatchQoS.QoSClass.userInteractive,6 2016-11-15 11:46:12.927868 GraphicsContext[2099:635172] DispatchQoS.QoSClass.userInteractive,7 2016-11-15 11:46:12.927871 GraphicsContext[2099:635166] DispatchQoS.QoSClass.userInteractive,8 2016-11-15 11:46:12.928016 GraphicsContext[2099:635172] DispatchQoS.QoSClass.userInteractive,9 2016-11-15 11:46:12.928138 GraphicsContext[2099:635166] DispatchQoS.QoSClass.userInteractive,10 2016-11-15 11:46:12.928719 GraphicsContext[2099:635113] DispatchQoS.QoSClass.default,1 2016-11-15 11:46:12.928817 GraphicsContext[2099:635166] DispatchQoS.QoSClass.unspecified,1 2016-11-15 11:46:12.928924 GraphicsContext[2099:635172] DispatchQoS.QoSClass.userInitiated,1 2016-11-15 11:46:12.929190 GraphicsContext[2099:635173] DispatchQoS.QoSClass.default,2 2016-11-15 11:46:12.929225 GraphicsContext[2099:635171] DispatchQoS.QoSClass.utility,1 2016-11-15 11:46:12.929723 GraphicsContext[2099:635174] DispatchQoS.QoSClass.unspecified,2 2016-11-15 11:46:12.930104 GraphicsContext[2099:635176] DispatchQoS.QoSClass.userInitiated,2 2016-11-15 11:46:12.930131 GraphicsContext[2099:635175] DispatchQoS.QoSClass.utility,2 2016-11-15 11:46:12.930641 GraphicsContext[2099:635177] DispatchQoS.QoSClass.default,3 2016-11-15 11:46:12.931705 GraphicsContext[2099:635179] DispatchQoS.QoSClass.unspecified,3 2016-11-15 11:46:12.931857 GraphicsContext[2099:635180] DispatchQoS.QoSClass.userInitiated,3 2016-11-15 11:46:12.932196 GraphicsContext[2099:635181] DispatchQoS.QoSClass.default,4 2016-11-15 11:46:12.932277 GraphicsContext[2099:635178] DispatchQoS.QoSClass.utility,3 2016-11-15 11:46:12.932779 GraphicsContext[2099:635183] DispatchQoS.QoSClass.unspecified,4 2016-11-15 11:46:12.932889 GraphicsContext[2099:635182] DispatchQoS.QoSClass.userInitiated,4 2016-11-15 11:46:12.933215 GraphicsContext[2099:635185] DispatchQoS.QoSClass.default,5 2016-11-15 11:46:12.933027 GraphicsContext[2099:635184] DispatchQoS.QoSClass.utility,4 2016-11-15 11:46:12.933423 GraphicsContext[2099:635113] DispatchQoS.QoSClass.unspecified,5 2016-11-15 11:46:12.933586 GraphicsContext[2099:635166] DispatchQoS.QoSClass.userInitiated,5 2016-11-15 11:46:12.933709 GraphicsContext[2099:635172] DispatchQoS.QoSClass.default,6 2016-11-15 11:46:12.933831 GraphicsContext[2099:635173] DispatchQoS.QoSClass.unspecified,6 2016-11-15 11:46:12.933976 GraphicsContext[2099:635174] DispatchQoS.QoSClass.userInitiated,6 2016-11-15 11:46:12.934095 GraphicsContext[2099:635176] DispatchQoS.QoSClass.default,7 2016-11-15 11:46:12.934242 GraphicsContext[2099:635177] DispatchQoS.QoSClass.unspecified,7 2016-11-15 11:46:12.934356 GraphicsContext[2099:635179] DispatchQoS.QoSClass.userInitiated,7 2016-11-15 11:46:12.934503 GraphicsContext[2099:635180] DispatchQoS.QoSClass.default,8 2016-11-15 11:46:12.934611 GraphicsContext[2099:635171] DispatchQoS.QoSClass.utility,5 2016-11-15 11:46:12.934701 GraphicsContext[2099:635175] DispatchQoS.QoSClass.utility,6 2016-11-15 11:46:12.937166 GraphicsContext[2099:635186] DispatchQoS.QoSClass.unspecified,8 2016-11-15 11:46:12.937476 GraphicsContext[2099:635188] DispatchQoS.QoSClass.userInitiated,8 2016-11-15 11:46:12.937521 GraphicsContext[2099:635187] DispatchQoS.QoSClass.utility,7 2016-11-15 11:46:12.937682 GraphicsContext[2099:635181] DispatchQoS.QoSClass.default,9 2016-11-15 11:46:12.937868 GraphicsContext[2099:635183] DispatchQoS.QoSClass.unspecified,9 2016-11-15 11:46:12.937987 GraphicsContext[2099:635182] DispatchQoS.QoSClass.userInitiated,9 2016-11-15 11:46:12.938110 GraphicsContext[2099:635185] DispatchQoS.QoSClass.default,10 2016-11-15 11:46:12.938262 GraphicsContext[2099:635113] DispatchQoS.QoSClass.unspecified,10 2016-11-15 11:46:12.938381 GraphicsContext[2099:635166] DispatchQoS.QoSClass.userInitiated,10 2016-11-15 11:46:12.938692 GraphicsContext[2099:635178] DispatchQoS.QoSClass.utility,8 2016-11-15 11:46:12.938837 GraphicsContext[2099:635184] DispatchQoS.QoSClass.utility,9 2016-11-15 11:46:12.941483 GraphicsContext[2099:635174] DispatchQoS.QoSClass.utility,10 2016-11-15 11:46:12.949181 GraphicsContext[2099:635115] DispatchQoS.QoSClass.background,1 2016-11-15 11:46:12.949734 GraphicsContext[2099:635115] DispatchQoS.QoSClass.background,2 2016-11-15 11:46:12.950257 GraphicsContext[2099:635115] DispatchQoS.QoSClass.background,3 2016-11-15 11:46:12.950775 GraphicsContext[2099:635115] DispatchQoS.QoSClass.background,4 2016-11-15 11:46:12.951348 GraphicsContext[2099:635115] DispatchQoS.QoSClass.background,5 2016-11-15 11:46:12.952512 GraphicsContext[2099:635115] DispatchQoS.QoSClass.background,6 2016-11-15 11:46:12.953108 GraphicsContext[2099:635115] DispatchQoS.QoSClass.background,7 2016-11-15 11:46:12.953659 GraphicsContext[2099:635115] DispatchQoS.QoSClass.background,8 2016-11-15 11:46:12.954176 GraphicsContext[2099:635115] DispatchQoS.QoSClass.background,9 2016-11-15 11:46:12.954890 GraphicsContext[2099:635115] DispatchQoS.QoSClass.background,10原文链接:https://www.f2er.com/swift/322653.html