Tom
Tom

Reputation: 3637

cannot invoke dispatch_get_global_queue

I have this line of code:

let queue = dispatch_get_global_queue(DISPATCH_QUEUE_CONCURRENT, 0);

I get error

Cannot invoke dispatch_get_global_queue with an argument list of type (dispatch_queue_atr_t, Int)

Must be something I am missing...

Update:

When I use xcode codeinsight / dropdown of suggestions for what to input it suggests DISPATCH_QUEUE_CONCURRENT of type dispatch_queue_attr_t - however, when going into code I can (now) see the paramater it expects is long.

I was interesed in getting a queue that was using multiple threads which IO tasks could be grouped into. (i.e. I do not want o "stall" the queue waiting on downloading some file.) I read tthat was possible here:

https://developer.apple.com/library/ios/documentation/General/Conceptual/ConcurrencyProgrammingGuide/OperationQueues/OperationQueues.html

Which mentions DISPATCH_QUEUE_CONCURRENT - however, I think that is only used when creating own queues - I just did not realize this originally

Upvotes: 1

Views: 519

Answers (3)

Pushpa Y
Pushpa Y

Reputation: 1010

Use any one of this type of dispatch_queue_priority_t

DISPATCH_QUEUE_PRIORITY_HIGH,
DISPATCH_QUEUE_PRIORITY_DEFAULT,
DISPATCH_QUEUE_PRIORITY_LOW,
DISPATCH_QUEUE_PRIORITY_BACKGROUND 

For more knowledge about queue :

Reference http://www.appcoda.com/ios-concurrency/

Hope it will help you :)

Upvotes: 1

Leo
Leo

Reputation: 24714

Should be

let queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

All global queue

#define DISPATCH_QUEUE_PRIORITY_HIGH        2
#define DISPATCH_QUEUE_PRIORITY_DEFAULT     0
#define DISPATCH_QUEUE_PRIORITY_LOW         (-2)
#define DISPATCH_QUEUE_PRIORITY_BACKGROUND  INT16_MIN

Upvotes: 2

Duyen-Hoa
Duyen-Hoa

Reputation: 15804

dispatch_get_global_queue takes long as 1st parameter, not an dispatch_queue_attr_t which is NSObject.

dispatch_queue_t dispatch_get_global_queue( long identifier, unsigned long flags);

As described in the document, you can specify dispatch_queue_priority_t value or if your develop for iOS >= 8.0, you can use QOS_CLASS_USER_INTERACTIVE, QOS_CLASS_USER_INITIATED, QOS_CLASS_UTILITY, or QOS_CLASS_BACKGROUND

https://developer.apple.com/library/ios/documentation/Performance/Reference/GCD_libdispatch_Ref/#//apple_ref/c/func/dispatch_get_global_queue

Upvotes: 2

Related Questions