Fucking Approachable Swift Concurrency

Swift Concurrency can feel like a lot of concepts: async/await, Task, actors, MainActor, Sendable, isolation domains. But there's really just one idea at the center of it all: isolation is inherited by default.

With Approachable Concurrency enabled, your app starts on MainActor. That's your starting point. From there:

  • Every function you call inherits that isolation
  • Every closure you create captures that isolation
  • Every Task { } you spawn inherits that isolation

You don't have to annotate anything. You don't have to think about threads. Your code runs on MainActor, and the isolation just propagates through your program automatically.

When you need to break out of that inheritance, you do it explicitly:

  • @concurrent says "run this on a background thread"
  • actor says "this type has its own isolation domain"
  • Task.detached { } says "start fresh, inherit nothing"

And when you pass data between isolation domains, Swift checks that it's safe. That's what Sendable is for: marking types that can safely cross boundaries.

That's it. That's the whole model:

  1. Isolation propagates from MainActor through your code
  2. You opt out explicitly when you need background work or separate state
  3. Sendable guards the boundaries when data crosses between domains

When the compiler complains, it's telling you one of these rules was violated. Trace the inheritance: where did the isolation come from? Where is the code trying to run? What data is crossing a boundary? The answer is usually obvious once you ask the right question.

fuckingapproachableswiftconcurrency.com

This is an excellent explanation of Swift Concurrency. It covers key ideas like async and await, actors, tasks, and structured ways to handle work in the background. The text makes hard topics clear and easy to follow.

People who build apps with Swift will find it helpful. It is worth the time to read. Keep it as a bookmark for later use. Share it with others who code in Swift so they can learn too.


Enjoyed this post?

Well, you could follow me, send me a comment via email, and/or leave a donation in the Tip Jar.


Tags

Category:

Tag:

Year: