Member-only story

What you should know about Grand Central Dispatch (GCD) in iOS

Are you tired of spending hours trying to figure out why your app is freezing? Well, have no fear, because GCD (Grand Central Dispatch) is here to save the day!

Brahim Siempay
4 min readJan 26, 2023
Photo by airfocus on Unsplash

Grand Central Dispatch or (GCD)

GCD is a tool that allows you to perform tasks asynchronously, which means that your app can continue to function while the task is being completed. This can be a lifesaver when it comes to preventing your app from freezing.

But, you might be wondering, “how do I use GCD?” Well, let me tell you, it’s not rocket science (although it might feel like it at first). There are a few different ways to use GCD, but I’ll focus on the main ones: .main and .global.

.main

DispatchQueue.main is used for tasks that need to be performed on the main thread. This is important because the main thread is responsible for updating the user interface. So, if you're trying to update a label or a button, you'll want to use .main.

Here’s an example of how to use .main:

DispatchQueue.main.async {
self.label.text = "Hello, World!"
}

Main thread checker

--

--

Brahim Siempay
Brahim Siempay

Responses (1)