GCD I
Executing tasks in parallel.
GCD I
Executing tasks in parallel.
0
0
Checkbox to mark video as read
Mark as read

In Swift, a thread refers to a single sequence of execution within a program. By default, code runs on the main thread, which handles tasks sequentially, one after another. This thread is especially important for UI updates.

To prevent the main thread from becoming unresponsive (e.g., when performing long tasks like data fetching), Swift uses concurrency with multiple threads. Apple provides Grand Central Dispatch (GCD), allowing developers to run tasks in parallel on different threads using queues, ensuring smoother app performance without freezing the UI.

There are 3 types of queues that execute with different priorities:

  • Main Queue
  • Global Queue
  • Custom Queue

Main Queue

The Main Queue has the highest priority and is where we should run UI-related operations to avoid crashes. This is used by default, but if we use another queue, we should execute UI-related changes on the Main Queue like this:

DispatchQueue.main.async {
    myLabel.text = "Hello"
}

Continue reading

Access to all the content with our plans.

Basic Plan

FREE

Start Now
  • Junior level content
  • Senior level content
  • Expert level content
  • Extra content
  • Question submissions
Monthly
Yearly

Plan logo

-

Unlimited access to the whole content

  • Junior level content
  • Senior level content
  • Expert level content
  • Extra content
  • Question submissions

Stripe secure payment methods
Plan logo

-

Unlimited access to the whole content

  • Junior level content
  • Senior level content
  • Expert level content
  • Extra content
  • Question submissions

Stripe secure payment methods
Plan logo

-

Solve your doubts at any level

  • Junior level content
  • Senior level content
  • Expert level content
  • Extra content
  • 2 Question submissions per week

Stripe secure payment methods
Plan logo

-

Solve your doubts at any level

  • Junior level content
  • Senior level content
  • Expert level content
  • Extra content
  • 2 Question submissions per week

Stripe secure payment methods

0 Comments

Join the community to comment
Sign Up
I have an account
Be the first to comment

Accept Cookies

We use cookies to collect and analyze information on site performance and usage, in order to provide you with better service.

Check our Privacy Policy