Target parameter in DispatchQueue

In Swift 3, an instance of DispatchQueue is created:

DispatchQueue(label: String,
              qos: DispatchQoS,
              attributes: DispatchQueue.Attributes,
              autoreleaseFrequency: DispatchQueue.AutoreleaseFrequency, 
              target: DispatchQueue?)

I see code samples from StackOverFlow, it can be nil, .global () or .main, what is the value of this parameter target?

I think .main means the queue will be started in the main thread, but why .nil or .global ()?

+9
source share
2 answers

There is no documentation for Swift, so I went back to the old documentation for GCD. The closest I found for the function : dispatch_set_target_queue

. , . , :

:

. dispatch_get_global_queue .

, , , .

, target 2 :

  1. (deinit)

, . Xcode, .

+9

:

" . dispatch_get_global_queue . , - , , . "

https://developer.apple.com/reference/dispatch/1452989-dispatch_set_target_queue

1. .main . , , , . .

2. .global , . , . Low, Default & High. 3 .

3. nil - . , .

.main target

.global ,

nil , - ( , )

+3

Source: https://habr.com/ru/post/1660954/


All Articles