Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use dispatch_queue_create in Swift 2.0?

Tags:

swift2

In swift 1.2, create a dispatch queue just like this:

dispatch_queue_create("imageProcessingQueue", DISPATCH_QUEUE_SERIAL)

But in swift 2.0, it has an error:

 Cannot invoke 'dispatch_queue_create' with an argument list of type '(String, dispatch_queue_attr_t!)'

dispatch_queue_create want an UnsafePointer<Int8> type, how can I get that.

like image 993
leavez Avatar asked Aug 10 '15 06:08

leavez


2 Answers

I had this issue too, when assigning to a lazy var. I was able to bypass the error by explicitly adding a type to my variable:

lazy var myQueue: dispatch_queue_t = dispatch_queue_create("imageProcessingQueue", DISPATCH_QUEUE_SERIAL)
like image 178
nate Avatar answered Nov 03 '22 01:11

nate


The error message is confusing. Most likely it originates from some code surrounding (most likely immediately preceding) this code.

To verify, create a new Playground and run this - it compiles without errors:

import Foundation
let queue = dispatch_queue_create("label", DISPATCH_QUEUE_SERIAL)
like image 24
Mundi Avatar answered Nov 02 '22 23:11

Mundi