The difference between dispatch_get_main_queue and dispatch_get_global_queue

I just started working on iOS and was compiling GCD stuff through the Apple Reference. dispatch_get_global _queue returns a parallel queue to which the executable block can be sent.

However, we can achieve the same using dispatch_get_main_queue , right? Then what is the difference between dispatch_get_global_queue and dispatch_get_main_queue ?

+4
source share
2 answers

The global queue is a background queue and executes its blocks on a non-main thread. The main queue executes its blocks in the main thread.

You must put background jobs that are not related to user interface changes in the global queue, but use the main queue when blocks make changes to the user interface. For example, a very general template is to execute the β€œwork” block in the global queue and the work block itself to go back to the main queue in order to update the progress indicator.

+9
source

dispatch_get_main_queue - should be used when you want to manipulate user interface elements. (It receives a background queue that you can send background tasks that are executed asynchronously ... it will not block your user interface)

dispatch_get_global_queue - Can be used for network calls / master data.

+4
source

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


All Articles