スキル一覧に戻る
goodevibes

modern-swift

by goodevibes

Copilot Plugin for Xcode using CoPilot

0🍴 0📅 2026年1月9日
GitHubで見るManusで実行

SKILL.md


name: modern-swift description: Use when writing async/await code, enabling strict concurrency, fixing Sendable errors, migrating from completion handlers, managing shared state with actors, or using Task/TaskGroup for concurrency.

Modern Swift (6.2+)

Swift 6.2 introduces strict compile-time concurrency checking with async/await, actors, and Sendable constraints that prevent data races at compile time instead of runtime. This is the foundation of safe concurrent Swift.

Overview

Modern Swift replaces older concurrency patterns (completion handlers, DispatchQueue, locks) with compiler-enforced safety. The core principle: if it compiles with strict concurrency enabled, it cannot have data races.

Quick Reference

NeedUseNOT
Async operationasync/awaitCompletion handlers
Main thread work@MainActorDispatchQueue.main
Shared mutable stateactorLocks, serial queues
Parallel tasksTaskGroupDispatchGroup
Thread safetySendable@unchecked everywhere

Core Workflow

When writing async Swift code:

  1. Mark async functions with async, call with await
  2. Apply @MainActor to view models and UI-updating code
  3. Use actor instead of locks for shared mutable state
  4. Check Task.isCancelled or call Task.checkCancellation() in loops
  5. Enable strict concurrency in Package.swift for compile-time safety

References

Load these based on what you need:

  • Concurrency Essentials — Load when writing new async code or converting completion handlers
  • Swift 6 Concurrency — Load when using @concurrent, nonisolated(unsafe), or actor patterns
  • Task Groups — Load when running multiple async operations in parallel
  • Task Cancellation — Load when implementing long-running or cancellable operations
  • Strict Concurrency — Load when enabling Swift 6 strict mode or fixing Sendable errors
  • Macros — Load when using or understanding Swift macros like @Observable
  • Modern Attributes — Load when migrating legacy code or using @preconcurrency, @backDeployed
  • Migration Patterns — Load when modernizing delegate patterns or UIKit views

Common Mistakes

  1. @unchecked Sendable as a quick fix — Using @unchecked Sendable to silence compiler errors means you've opted out of safety. If the error persists after @unchecked, your code has a potential data race. Fix the underlying issue instead.

  2. Missing await at call sites — Forgetting await when calling async functions is a compiler error, but checking Task.isCancelled in a loop without calling Task.checkCancellation() silently ignores cancellation.

  3. Capturing self in async blocks without weak — Holding a strong reference to self in a long-running async task prevents deinit. Always use [weak self] in closures or use .task which auto-manages the lifecycle.

  4. Not checking task cancellation — Long-running operations should regularly check Task.isCancelled or call Task.checkCancellation(), otherwise cancellation signals are ignored.

  5. Forgetting @MainActor on UI code and test suites — Main test struct and view models that update @Published properties need @MainActor. Forgetting it silently allows cross-thread mutations. Apply @MainActor to: view models, view structs, main test structs, and any type that touches UI.

  6. Actor re-entrancy surprisesawait inside an actor method can release the lock temporarily. Another task may modify actor state. Design actor methods assuming state can change between await points.

スコア

総合スコア

60/100

リポジトリの品質指標に基づく評価

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

+10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

レビュー

💬

レビュー機能は近日公開予定です