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

Next
About this episode

Leave a rating/review

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

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

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

Throughout this course, whenever you’ve needed to make quick changes that drive the UI, you’ve called MainActor.run(...) 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 { 
  // ...
}