swift-concurrency

Coding rules for Swift 6 programs that run asynchronous work, meaning tasks that can proceed without blocking the app.

In plain words
What is it for?
Use them when writing async/await code, actors, @MainActor UI code, structured concurrency, or Sendable types.
Why use it?
They help prevent unsafe access to shared data and errors when background work interacts with the user interface.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/getsentry/xcodebuildmcp-ios-template/swift-concurrency
Clone the repo
git clone --depth 1 https://github.com/getsentry/XcodeBuildMCP-iOS-Template

Made for: Cursor.

Per session 48 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,600 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00048 $0.01600
Opus 5 $0.00024 $0.00800
Sonnet 5 $0.00010 $0.00320
Haiku 4.5 $0.00005 $0.00160

Measured 2d ago against content hash 77d811e1a08c, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

swift-concurrency scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

template/.cursor/rules/swift-concurrency.mdc · 272 lines

How it starts

The opening of the file, as written. The whole thing — 272 lines — stays where its author put it; the contents beside it link to each section on GitHub.

name: "Swift Concurrency Guidelines" description: "Swift 6 strict concurrency patterns, actor isolation, @MainActor usage, async/await best practices, structured concurrency, and Sendable conformance. Apply when working with async code, actors, concurrent operations, or resolving concurrency warnings/errors." agent_requested: true applies_to: ["**/*.swift"]

Swift Concurrency Guidelines

Actor Isolation (Swift 6 Strict Mode)

All code must follow Swift 6 strict concurrency rules. The project uses strict concurrency mode as configured in MyProjectPackage/Package.swift.

@MainActor for UI Code

All UI-related code must be isolated to the main actor:

@MainActor
struct ContentView: View {
    @State private var model = DataModel()
    
    var body: some View {
        // All UI code runs on main actor
        List(model.items) { item in
            Text(item.title)
        }
    }
}

@MainActor
class UIModel: ObservableObject {
    @Published var state: ViewState = .idle
    
    func updateUI() {
        // Safe to update UI properties here
        state = .loaded
    }
}

Actors for Shared Mutable State

Use actors for managing shared mutable state safely:

actor DataStore {
    private var items: [Item] = []
    
    func addItem(_ item: Item) {
        items.append(item)
    }
    
    func getItems() -> [Item] {
        return items
    }
}

Async/Await Patterns

Required: Use .task Modifier in Views

Always use .task for async operations tied to view lifecycle:

// ✅ CORRECT: Use .task for view lifecycle
struct DataView: View {
    @State private var items: [Item] = []
    
    var body: some View {
        List(items, id: \.id) { item in
            Text(item.name)
        }
        .task {
            // Automatically cancels when view disappears
            do {
                items = try await loadItems()
            } catch {
                // Handle error
            }
        }
    }
}

Read the full file on GitHub · 272 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 272 lines · 48 tokens per session scan A 77d811e1a08c

Subscribe to this mod's changes

swift-concurrency is a cursor rule published in the GitHub repository getsentry/XcodeBuildMCP-iOS-Template (43 stars, last pushed 1y ago), licensed MIT. It adds 48 tokens to every session and 1,600 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.