Global Actors in Swift Concurrency

Everywhere!

Steven Curtis
3 min readAug 28, 2023
Photo by Kyle Glenn on Unsplash

Introduced in Swift 5.5 along with Swift’s new concurrency model, global actors provide synchronization and ensure correct data access.

Let’s take a look.

Difficulty: Beginner | Easy | Normal | Challenging

This article has been developed using Xcode 14.2, and Swift 5.7.2

Prerequisites

- Be able to produce a “Hello, World!” SwiftUI project

It might be nice if you had some knowledge of:

- Actors are a conceptual model used to deal with concurrency

- Be familiar with @MainActor

Keywords and Terminology

@MainActor: is a Swift attribute used to indicate that a type or function must be executed on the main thread.

Global Actors: Singleton actors which can be used to provide synchronization and ensure correct data access in concurrent contexts

Singleton: A way of instantiation that guarantees that only one instance of a class is created

Is a global actor the same as a main actor?

Not quite.

--

--