Getting the Main Queue

suggest change

The main queue is the dispatch queue on which UI updates run.

Update the UI on the main queue when an asynchronous process such as NSURLSession finishes. dispatch_sync on the main queue from the main queue deadlocks. The Objective-C “synchronous” sample below was dispatch_get_global_queue, which is not the main queue.

There are two types of main queue calls synchronous and asynchronous. When you invoke something synchronously, it means that the thread that initiated that operation will wait for the task to finish before continuing. Asynchronous means that it will not wait.

Code Objective-C

Synchronous Main Queue call

dispatch_sync(dispatch_get_main_queue(), ^{
   // do work here to update the user interface
});

Asynchronous Main Queue call

dispatch_async(dispatch_get_main_queue(), ^{
   // do work here to Usually to update the User Interface
});

SWIFT 3

Asynchronous Main Queue call

DispatchQueue.main.async {

}

Synchronous Main Queue call

DispatchQueue.main.sync {

}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents