Introduction

Introduction

When your app does many things at once — downloading data, saving files, updating the UI — it’s easy for two pieces of code to touch the same data at the same time. That’s how bugs like “last write wins” or “I saved the wrong value” happen.

Swift solves this with actors. An actor is like a tiny office with one door and one clerk. Only one caller can be helped at a time. Everyone else waits in a line (a queue). That gives you exclusive, serialized access to the actor’s stored properties, which prevents data races.

By the end of this lesson, you will:

  • Explain exclusive, serialized access and actor isolation in plain language.
  • Call actor methods correctly with await, and know when nonisolated is appropriate.
  • Recognize and avoid reentrancy hazards by committing state before await.
  • Use @MainActor for UI code and a custom global actor to serialize disk I/O.
  • Build and run a small iOS app that uses an actor-backed image cache.
See forum comments
Download course materials from Github
Previous: Quiz for Lesson 3 Next: A Guide to Swift Actors