【发布时间】:2016-08-21 20:58:06
【问题描述】:
NSOperationQueue 类有一个underlyingQueue 属性,用于设置将在其上执行NSOperation 实例的调度队列。
let dispatchQueue = dispatch_queue_create("custom.queue", DISPATCH_QUEUE_SERIAL)
let opQueue = NSOperationQueue()
opQueue.underlyingQueue = dispatchQueue
但是,官方文档指出:
该属性的值不能是
dispatch_get_main_queue返回的值
Apple 似乎没有对这个主题做出更多解释。但是,将主队列用作underlyingQueue 不会引发任何错误,也不会产生任何不需要的行为。这背后的原因是什么?
【问题讨论】:
-
如果要使用主队列,为什么要调用
dispatch_queue_create?只需使用dispatch_get_main_queue。 -
dispatch_queue_create仅用作如何设置underlyingQueue属性的示例。正如您从文档中看到的那样,dispatch_get_main_queue不应用作底层队列。
标签: ios swift nsoperation nsoperationqueue