Swift Skill
Swift concurrency and testing: async/await, Actors, TaskGroups, Sendable, structured concurrency, XCTest, Swift Testing framework, and async test patterns.
Reference Loading Table
| Signal |
Reference |
Size |
| async/await, Task, Sendable |
references/fundamentals.md |
~20 lines |
| Actor, @MainActor, nonisolated |
references/actor-isolation.md |
~20 lines |
| TaskGroup, AsyncSequence, AsyncStream, cancellation |
references/task-patterns.md |
~20 lines |
| Failure modes, common mistakes |
references/preferred-patterns.md |
~20 lines |
| concurrency overview, structured concurrency patterns |
references/swift-concurrency.md |
~30 lines |
| XCTest, Swift Testing, test doubles, async tests, UI tests |
references/swift-testing.md |
~250 lines |
Loading rule. Read the references whose signals match the task before responding.
Core Rules (Always Apply)
Concurrency
- Prefer structured concurrency -- use
TaskGroup over loose Task { } whenever possible; structured tasks propagate cancellation and errors automatically.
- Mark types Sendable -- enable strict concurrency checking (
-strict-concurrency=complete) and resolve all warnings before they become errors in Swift 6.
- Use actors for shared mutable state -- avoid manual locks; actors provide compiler-verified safety.
- Cancel what you create -- every
Task stored in a property should have a corresponding cancellation path.
- Minimize @MainActor surface -- isolate only the UI layer; keep business logic and networking off the main actor.
Testing
- One assertion per concept -- a single test can have multiple assertions if they verify the same logical behavior, but avoid testing unrelated things together.
- Arrange-Act-Assert -- structure every test into setup, execution, and verification phases.
- Name tests descriptively --
testFetchUser_withExpiredToken_throwsAuthError is better than testFetch2.
- Prefer Swift Testing for new code -- use
@Test and #expect when targeting Swift 5.9+; fall back to XCTest for older targets or UI tests.
- Ensure test independence -- each test must be runnable in isolation; always produce self-contained test state.
Phase 1: ASSESS
Determine what kind of Swift work is needed:
| Request type |
Load references |
Action |
| Concurrency patterns |
fundamentals, actor-isolation, task-patterns |
Pattern guidance |
| Concurrency mistakes |
preferred-patterns |
Failure mode detection |
| Write tests |
swift-testing |
Test authoring |
| Async test patterns |
swift-testing + fundamentals |
Async test guidance |
| Full concurrency review |
swift-concurrency + all concurrency refs |
Full review pass |
Gate: Request classified and relevant references loaded.
Phase 2: EXECUTE
Apply loaded reference knowledge to the user's code or question.
For concurrency work:
- Verify structured concurrency used where possible
- Check Sendable conformance
- Validate actor isolation boundaries
- Confirm cancellation paths exist
For testing work:
- Use Swift Testing (
@Test, #expect) for new code on Swift 5.9+
- Use
@dataProvider-style parameterized tests with arguments:
- Use protocol-based mock injection
- Use XCTest for UI tests and older targets
Gate: Specific, reference-backed feedback or code provided.
Phase 3: VERIFY
Run the test suite and confirm:
swift test --enable-code-coverage
swift build
Gate: All tests pass. Build succeeds with strict concurrency checking.
1---2name: swift3description: "Swift development: concurrency patterns, async/await, actors, testing with XCTest and Swift Testing framework."4user-invocable: false5context: fork6agent: swift-general-engineer7routing:8 triggers:9 - "swift concurrency"10 - "swift async await"11 - "Swift Actor"12 - "Swift Task group"13 - "swift testing"14 - "XCTest"15 - "Swift Testing framework"16 - "async test swift"17 category: swift18 pairs_with:19 - test-driven-development20 - code-linting21---2223# Swift Skill2425Swift concurrency and testing: async/await, Actors, TaskGroups, Sendable, structured concurrency, XCTest, Swift Testing framework, and async test patterns.2627## Reference Loading Table2829| Signal | Reference | Size |30|--------|-----------|------|31| async/await, Task, Sendable | `references/fundamentals.md` | ~20 lines |32| Actor, @MainActor, nonisolated | `references/actor-isolation.md` | ~20 lines |33| TaskGroup, AsyncSequence, AsyncStream, cancellation | `references/task-patterns.md` | ~20 lines |34| Failure modes, common mistakes | `references/preferred-patterns.md` | ~20 lines |35| concurrency overview, structured concurrency patterns | `references/swift-concurrency.md` | ~30 lines |36| XCTest, Swift Testing, test doubles, async tests, UI tests | `references/swift-testing.md` | ~250 lines |3738**Loading rule.** Read the references whose signals match the task before responding.3940---4142## Core Rules (Always Apply)4344### Concurrency4546- **Prefer structured concurrency** -- use `TaskGroup` over loose `Task { }` whenever possible; structured tasks propagate cancellation and errors automatically.47- **Mark types Sendable** -- enable strict concurrency checking (`-strict-concurrency=complete`) and resolve all warnings before they become errors in Swift 6.48- **Use actors for shared mutable state** -- avoid manual locks; actors provide compiler-verified safety.49- **Cancel what you create** -- every `Task` stored in a property should have a corresponding cancellation path.50- **Minimize @MainActor surface** -- isolate only the UI layer; keep business logic and networking off the main actor.5152### Testing5354- **One assertion per concept** -- a single test can have multiple assertions if they verify the same logical behavior, but avoid testing unrelated things together.55- **Arrange-Act-Assert** -- structure every test into setup, execution, and verification phases.56- **Name tests descriptively** -- `testFetchUser_withExpiredToken_throwsAuthError` is better than `testFetch2`.57- **Prefer Swift Testing for new code** -- use `@Test` and `#expect` when targeting Swift 5.9+; fall back to XCTest for older targets or UI tests.58- **Ensure test independence** -- each test must be runnable in isolation; always produce self-contained test state.5960---6162## Phase 1: ASSESS6364Determine what kind of Swift work is needed:6566| Request type | Load references | Action |67|-------------|----------------|--------|68| Concurrency patterns | fundamentals, actor-isolation, task-patterns | Pattern guidance |69| Concurrency mistakes | preferred-patterns | Failure mode detection |70| Write tests | swift-testing | Test authoring |71| Async test patterns | swift-testing + fundamentals | Async test guidance |72| Full concurrency review | swift-concurrency + all concurrency refs | Full review pass |7374**Gate**: Request classified and relevant references loaded.7576---7778## Phase 2: EXECUTE7980Apply loaded reference knowledge to the user's code or question.8182For concurrency work:831. Verify structured concurrency used where possible842. Check Sendable conformance853. Validate actor isolation boundaries864. Confirm cancellation paths exist8788For testing work:891. Use Swift Testing (`@Test`, `#expect`) for new code on Swift 5.9+902. Use `@dataProvider`-style parameterized tests with `arguments:`913. Use protocol-based mock injection924. Use XCTest for UI tests and older targets9394**Gate**: Specific, reference-backed feedback or code provided.9596---9798## Phase 3: VERIFY99100Run the test suite and confirm:101102```bash103swift test --enable-code-coverage104swift build105```106107**Gate**: All tests pass. Build succeeds with strict concurrency checking.