[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill-c785e0c5-693e-4485-ab3b-a7be95c352cc":3,"$f6QRzHcvQqM9pLwj37tG-Ns269SR2nTUtMNHc_UCruTg":43},{"id":4,"title":5,"description":6,"categoryId":7,"moduleId":8,"tags":9,"prompt":10,"icon":11,"source":12,"sourceUrl":13,"authorId":14,"authorName":15,"isPublic":16,"stars":17,"runs":18,"createdAt":19,"updatedAt":19,"module":20,"category":27,"packages":34},"c785e0c5-693e-4485-ab3b-a7be95c352cc","swift-concurrency-expert","审查和修复Swift并发问题，例如actor隔离和Sendable违规。","cat_coding_frontend","mod_coding","sickn33,coding","---\nname: swift-concurrency-expert\ndescription: Review and fix Swift concurrency issues such as actor isolation and Sendable violations.\nrisk: safe\nsource: \"Dimillian\u002FSkills (MIT)\"\ndate_added: \"2026-03-25\"\n---\n\n# Swift Concurrency Expert\n\n## Overview\n\nReview and fix Swift Concurrency issues in Swift 6.2+ codebases by applying actor isolation, Sendable safety, and modern concurrency patterns with minimal behavior changes.\n\n## When to Use\n- When the user asks to review Swift concurrency usage or fix compiler diagnostics.\n- When you need guidance on actor isolation, `Sendable`, `@MainActor`, or async migration.\n\n## Workflow\n\n### 1. Triage the issue\n\n- Capture the exact compiler diagnostics and the offending symbol(s).\n- Check project concurrency settings: Swift language version (6.2+), strict concurrency level, and whether approachable concurrency (default actor isolation \u002F main-actor-by-default) is enabled.\n- Identify the current actor context (`@MainActor`, `actor`, `nonisolated`) and whether a default actor isolation mode is enabled.\n- Confirm whether the code is UI-bound or intended to run off the main actor.\n\n### 2. Apply the smallest safe fix\n\nPrefer edits that preserve existing behavior while satisfying data-race safety.\n\nCommon fixes:\n- **UI-bound types**: annotate the type or relevant members with `@MainActor`.\n- **Protocol conformance on main actor types**: make the conformance isolated (e.g., `extension Foo: @MainActor SomeProtocol`).\n- **Global\u002Fstatic state**: protect with `@MainActor` or move into an actor.\n- **Background work**: move expensive work into a `@concurrent` async function on a `nonisolated` type or use an `actor` to guard mutable state.\n- **Sendable errors**: prefer immutable\u002Fvalue types; add `Sendable` conformance only when correct; avoid `@unchecked Sendable` unless you can prove thread safety.\n\n### 3. Verify the fix\n\n- Rebuild and confirm all concurrency diagnostics are resolved with no new warnings introduced.\n- Run the test suite to check for regressions — concurrency changes can introduce subtle runtime issues even when the build is clean.\n- If the fix surfaces new warnings, treat each one as a fresh triage (return to step 1) and resolve iteratively until the build is clean and tests pass.\n\n### Examples\n\n**UI-bound type — adding `@MainActor`**\n\n```swift\n\u002F\u002F Before: data-race warning because ViewModel is accessed from the main thread\n\u002F\u002F but has no actor isolation\nclass ViewModel: ObservableObject {\n    @Published var title: String = \"\"\n    func load() { title = \"Loaded\" }\n}\n\n\u002F\u002F After: annotate the whole type so all stored state and methods are\n\u002F\u002F automatically isolated to the main actor\n@MainActor\nclass ViewModel: ObservableObject {\n    @Published var title: String = \"\"\n    func load() { title = \"Loaded\" }\n}\n```\n\n**Protocol conformance isolation**\n\n```swift\n\u002F\u002F Before: compiler error — SomeProtocol method is nonisolated but the\n\u002F\u002F conforming type is @MainActor\n@MainActor\nclass Foo: SomeProtocol {\n    func protocolMethod() { \u002F* accesses main-actor state *\u002F }\n}\n\n\u002F\u002F After: scope the conformance to @MainActor so the requirement is\n\u002F\u002F satisfied inside the correct isolation context\n@MainActor\nextension Foo: SomeProtocol {\n    func protocolMethod() { \u002F* safely accesses main-actor state *\u002F }\n}\n```\n\n**Background work with `@concurrent`**\n\n```swift\n\u002F\u002F Before: expensive computation blocks the main actor\n@MainActor\nfunc processData(_ input: [Int]) -> [Int] {\n    input.map { heavyTransform($0) }   \u002F\u002F runs on main thread\n}\n\n\u002F\u002F After: hop off the main actor for the heavy work, then return the result\n\u002F\u002F The caller awaits the result and stays on its own actor\nnonisolated func processData(_ input: [Int]) async -> [Int] {\n    await Task.detached(priority: .userInitiated) {\n        input.map { heavyTransform($0) }\n    }.value\n}\n\n\u002F\u002F Or, using a @concurrent async function (Swift 6.2+):\n@concurrent\nfunc processData(_ input: [Int]) async -> [Int] {\n    input.map { heavyTransform($0) }\n}\n```\n\n## Reference material\n\n- See `references\u002Fswift-6-2-concurrency.md` for Swift 6.2 changes, patterns, and examples.\n- See `references\u002Fapproachable-concurrency.md` when the project is opted into approachable concurrency mode.\n- See `references\u002Fswiftui-concurrency-tour-wwdc.md` for SwiftUI-specific concurrency guidance.\n\n## Limitations\n- Use this skill only when the task clearly matches the scope described above.\n- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.\n- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.\n","","imported","https:\u002F\u002Fgithub.com\u002Fsickn33\u002Fantigravity-awesome-skills","user_system_seed","SkillOPIC",true,147,1499,"2026-05-16 13:42:37",{"id":8,"name":21,"slug":22,"icon":23,"description":24,"sort":25,"createdAt":26},"编程开发","coding","mdi-code-braces","代码生成、调试、审查，提升开发效率",2,"2026-05-16 12:53:40",{"id":7,"name":28,"slug":29,"icon":30,"description":31,"moduleId":8,"sort":32,"skillCount":33,"createdAt":26},"前端开发","frontend","mdi-language-html5","HTML\u002FCSS\u002FJavaScript\u002F框架相关",1,96,[35],{"id":36,"skillId":4,"version":37,"fileName":38,"fileSize":39,"filePath":40,"fileHash":41,"manifest":42,"createdAt":19},"5819dcca-aa0e-4534-99d9-b4430b07d973","1.0.0","swift-concurrency-expert.zip",8017,"uploads\u002Fskills\u002Fc785e0c5-693e-4485-ab3b-a7be95c352cc\u002Fswift-concurrency-expert.zip","54a7b17c95a09720dc1e9d8e95e9c49de8f0087845c8f5ac39fb2f2870faa5d5","[{\"path\":\"SKILL.md\",\"isDirectory\":false,\"size\":4610},{\"path\":\"agents\u002Fopenai.yaml\",\"isDirectory\":false,\"size\":243},{\"path\":\"references\u002Fapproachable-concurrency.md\",\"isDirectory\":false,\"size\":2471},{\"path\":\"references\u002Fswift-6-2-concurrency.md\",\"isDirectory\":false,\"size\":10673},{\"path\":\"references\u002Fswiftui-concurrency-tour-wwdc.md\",\"isDirectory\":false,\"size\":1645}]",{"code":44,"message":45,"data":46},200,"success",{"items":47,"stats":48,"page":51},[],{"averageRating":49,"totalRatings":49,"ratingCounts":50},0,[49,49,49,49,49],{"limit":52,"offset":49,"hasMore":53,"nextOffset":52,"ratedOnly":16},15,false]