Modern Concurrency: Beyond the Basics

Oct 20 2022 Swift 5.5, iOS 15, Xcode 13.4

Part 2: Concurrent Code

16. GlobalActor

Episode complete

Play next episode

Save for later
About this episode
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 15. Writing Safe Concurrent Code With Actors Next episode: 17. Creating a GlobalActor

This video GlobalActor was last updated on Oct 20 2022

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

You can unlock the rest of this video course, and our entire catalogue of books and videos, with a Professional subscription.

Throughout this course, whenever you’ve needed to make quick changes that drive the UI, you’ve called to access MainActor from anywhere. Because your app runs on a single main thread, you can’t create a second or a third MainActor. So it does make sense that there’s a default, shared instance of that actor that you can safely use from anywhere.

@globalActor actor ImageDatabase {
  static let shared = ImageDatabase()
  // ...
@ImageDatabase func say(_ text: String) {
  // ... automatically runs on ImageDatabase ...

@ImageDatabase class DiskStorage { 
  // ...