Swift Concurrency logo

Swift Concurrency

Community
jamesrochabrun
swift-concurrency

Guide for building, auditing, and refactoring Swift code using modern concurrency patterns (Swift 6+). This skill should be used when working with async/await, Tasks, actors, MainActor, Sendable types, isolation domains, or when migrating legacy callback/Combine code to structured concurrency. Covers Approachable Concurrency settings, isolated parameters, and common pitfalls.

Overview

Publisherjamesrochabrun
Repositoryskills
Skill nameswift-concurrency
Stars
209
Forks
25
Bundled files
5
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 5 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by jamesrochabrun on GitHub. Read the source before you install it.

Installation

Install the Swift Concurrency AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/jamesrochabrun/skills.git /tmp/skills
mkdir -p .claude/skills
cp -r /tmp/skills/skills/swift-concurrency .claude/skills/swift-concurrency
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Swift Concurrency in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Swift Concurrency on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Swift Concurrency is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Swift Concurrency

Overview

This skill provides guidance for writing thread-safe Swift code using modern concurrency patterns. It covers three main workflows: building new async code, auditing existing code for issues, and refactoring legacy patterns to Swift 6+.

Core principle: Isolation is inherited by default. With Approachable Concurrency, code starts on MainActor and propagates through the program automatically. Opt out explicitly when needed.

Workflow Decision Tree

What are you doing?
├─► BUILDING new async code
│   └─► See "Building Workflow" below
├─► AUDITING existing code
│   └─► See "Auditing Checklist" below
└─► REFACTORING legacy code
    └─► See "Refactoring Workflow" below

Building Workflow

When writing new async code, follow this decision process:

Step 1: Determine Isolation Needs

Does this type manage UI state or interact with UI?
├─► YES → Mark with @MainActor
└─► NO → Does it have mutable state shared across contexts?
         ├─► YES → Consider: Can it live on MainActor anyway?
         │         │
         │         ├─► YES → Use @MainActor (simpler)
         │         │
         │         └─► NO → Use a custom actor (requires justification)
         └─► NO → Leave non-isolated (default with Approachable Concurrency)

Step 2: Design Async Functions

swift
// PREFER: Inherit caller's isolation (works everywhere)
func fetchData(isolation: isolated (any Actor)? = #isolation) async throws -> Data {
  // Runs on whatever actor the caller is on
}

// USE WHEN: CPU-intensive work that must run in background
@concurrent
func processLargeFile() async -> Result { }

// AVOID: Non-isolated async without explicit choice
func ambiguousAsync() async { } // Where does this run?

Step 3: Handle Parallel Work

swift
// For known number of independent operations
async let avatar = fetchImage("avatar.jpg")
async let banner = fetchImage("banner.jpg")
let (a, b) = await (avatar, banner)

// For dynamic number of operations
try await withThrowingTaskGroup(of: Void.self) { group in
  for id in userIDs {
    group.addTask { try await fetchUser(id) }
  }
  try await group.waitForAll()
}

Step 4: SwiftUI Integration

swift
struct ProfileView: View {
  @State private var avatar: Image?

  var body: some View {
    avatar
      .task { avatar = await downloadAvatar() }  // Auto-cancels on disappear
      .task(id: userID) { /* Reloads when userID changes */ }
  }
}

// For user actions
Button("Save") {
  Task { await saveProfile() }  // Inherits MainActor isolation
}

Auditing Checklist

When reviewing Swift concurrency code, check for these issues:

Critical Issues (Must Fix)

  • Blocking the cooperative pool: Look for DispatchSemaphore.wait(), DispatchGroup.wait(), or similar blocking calls inside async contexts
  • Data races: Non-Sendable types crossing isolation boundaries without proper handling
  • Non-isolated async in non-Sendable types: These only work from non-isolated contexts

Common Issues (Should Fix)

  • Actor overuse: Custom actors without justification (see "Actor Justification Test" in references)
  • Unnecessary MainActor.run: Should usually be @MainActor on the function instead
  • Thinking async = background: Synchronous CPU work inside async functions still blocks
  • Unstructured Tasks where structured works: Task { } instead of async let or TaskGroup
  • Missing cancellation handling: Long operations should check Task.isCancelled

SwiftUI-Specific

  • Views not MainActor-isolated: SwiftUI views should be @MainActor (or use @Observable)
  • Accessing @State from detached tasks: Must hop back to MainActor

Sendable Compliance

  • @unchecked Sendable overuse: Should be rare and justified
  • Making everything Sendable: Not all types need to cross boundaries
  • Non-Sendable closures escaping: Check closure captures

Refactoring Workflow

From Callbacks to async/await

swift
// BEFORE: Callback-based
func fetchUser(id: Int, completion: @escaping (Result<User, Error>) -> Void) {
  URLSession.shared.dataTask(with: url) { data, _, error in
    if let error { completion(.failure(error)); return }
    // ...
  }.resume()
}

// AFTER: async/await with continuation
func fetchUser(id: Int) async throws -> User {
  try await withCheckedThrowingContinuation { continuation in
    fetchUser(id: id) { result in
      continuation.resume(with: result)
    }
  }
}

From DispatchQueue to Actors

swift
// BEFORE: Queue-based protection
class BankAccount {
  private let queue = DispatchQueue(label: "account")
  private var _balance: Double = 0

  var balance: Double {
    queue.sync { _balance }
  }

  func deposit(_ amount: Double) {
    queue.async { self._balance += amount }
  }
}

// AFTER: Actor (if truly needs own isolation)
actor BankAccount {
  var balance: Double = 0

  func deposit(_ amount: Double) {
    balance += amount
  }
}

// BETTER: MainActor class (if doesn't need concurrent access)
@MainActor
class BankAccount {
  var balance: Double = 0

  func deposit(_ amount: Double) {
    balance += amount
  }
}

From Combine to AsyncSequence

swift
// BEFORE: Combine publisher
cancellable = NotificationCenter.default
  .publisher(for: .userDidLogin)
  .sink { notification in /* ... */ }

// AFTER: AsyncSequence
for await _ in NotificationCenter.default.notifications(named: .userDidLogin) {
  // Handle notification
}

Quick Reference

KeywordPurpose
asyncFunction can suspend
awaitSuspension point
Task { }Start async work, inherits isolation
Task.detached { }Start async work, no inheritance
@MainActorRuns on main thread
actorType with isolated mutable state
nonisolatedOpts out of actor isolation
nonisolated(nonsending)Inherits caller's isolation
@concurrentAlways run on background (Swift 6.2+)
SendableSafe to cross isolation boundaries
sendingOne-way transfer of non-Sendable
async letStart parallel work
TaskGroupDynamic parallel work

Approachable Concurrency Settings (Swift 6.2+)

For new Xcode 26+ projects, these are enabled by default:

SWIFT_DEFAULT_ACTOR_ISOLATION = MainActor
SWIFT_APPROACHABLE_CONCURRENCY = YES

Effects:

  • Everything runs on MainActor unless explicitly marked otherwise
  • nonisolated async functions stay on caller's actor instead of hopping to background
  • Sendable errors become much rarer

Resources

For detailed technical reference, consult:

  • references/fundamentals.md - async/await, Tasks, structured concurrency
  • references/isolation.md - Actors, MainActor, isolation domains, inheritance
  • references/sendable.md - Sendable protocol, non-Sendable patterns, isolated parameters
  • references/common-mistakes.md - Detailed examples of what to avoid
  • references/glossary.md - Complete terminology reference

Search patterns for references:

  • Isolation: grep -i "isolation\|actor\|mainactor\|nonisolated"
  • Sendable: grep -i "sendable\|sending\|boundary"
  • Tasks: grep -i "task\|taskgroup\|async let\|structured"

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Swift Concurrency AI skill do?

Guide for building, auditing, and refactoring Swift code using modern concurrency patterns (Swift 6+). This skill should be used when working with async/await, Tasks, actors, MainActor, Sendable types, isolation domains, or when migrating legacy callback/Combine code to structured concurrency. Covers Approachable Concurrency settings, isolated parameters, and common pitfalls.

Why use Swift Concurrency on TypingMind?

Because you install it once and use it with any model. Swift Concurrency is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Swift Concurrency in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/jamesrochabrun/skills/tree/main/skills/swift-concurrency. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Swift Concurrency?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Swift Concurrency?

As many as you like. As long as a model supports skills, you can use Swift Concurrency with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Swift Concurrency AI skill free?

Yes. It is published on GitHub by jamesrochabrun under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇