如何在Swift 2.0中使用dispatch_queue_create?

lea*_*vez 9 swift2

在swift 1.2中,创建一个如下所示的调度队列:

dispatch_queue_create("imageProcessingQueue", DISPATCH_QUEUE_SERIAL)
Run Code Online (Sandbox Code Playgroud)

但在swift 2.0中,它有一个错误:

 Cannot invoke 'dispatch_queue_create' with an argument list of type '(String, dispatch_queue_attr_t!)'
Run Code Online (Sandbox Code Playgroud)

dispatch_queue_create想要一个UnsafePointer<Int8>类型,我怎么能得到它.

小智 11

分配到a时,我也有这个问题lazy var.我能够通过向我的变量显式添加一个类型来绕过错误:

lazy var myQueue: dispatch_queue_t = dispatch_queue_create("imageProcessingQueue", DISPATCH_QUEUE_SERIAL)
Run Code Online (Sandbox Code Playgroud)


Mun*_*ndi 1

错误消息令人困惑。它很可能源自围绕此代码(最有可能紧接在其之前)的某些代码。

要进行验证,请创建一个新的 Playground 并运行它 - 它编译时没有错误:

import Foundation
let queue = dispatch_queue_create("label", DISPATCH_QUEUE_SERIAL)
Run Code Online (Sandbox Code Playgroud)