[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M77Y7P15TNDA3VJNZK2YFZED":3,"skill-same:01M77Y7P15TNDA3VJNZK2YFZED":47},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":27,"repositoryHtmlUrl":28,"repositoryHomepageUrl":6,"ownerHtmlUrl":29,"ownerBlogUrl":30,"ownerDescription":31,"updatedAt":32,"install":33,"resources":46},"01M77Y7P15TNDA3VJNZK2YFZED","swift-concurrency-6-2",null,"Swift 6.2 Approachable Concurrency — single-threaded by default, @concurrent for explicit background offloading, isolated conformances for main actor types.","503496348-ops\u002Fmischief-production","503496348-ops","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F266905914?v=4","01M77X5J7XQWWZGT8998HDGXQM","AtomCollide","01M77X5J8V78Y3NXMY6BBC75X9",2,"MIT","https:\u002F\u002Fgithub.com\u002F503496348-ops\u002Fmischief-production\u002Fblob\u002Fmain\u002Fskills\u002Fecc-swift-concurrency-6-2\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: swift-concurrency-6-2\ndescription: Swift 6.2 Approachable Concurrency — single-threaded by default, @concurrent for explicit background offloading, isolated conformances for main actor types.\n---\n\n# Swift 6.2 Approachable Concurrency\n\nPatterns for adopting Swift 6.2's concurrency model where code runs single-threaded by default and concurrency is introduced explicitly. Eliminates common data-race errors without sacrificing performance.\n\n## When to Activate\n\n- Migrating Swift 5.x or 6.0\u002F6.1 projects to Swift 6.2\n- Resolving data-race safety compiler errors\n- Designing MainActor-based app architecture\n- Offloading CPU-intensive work to background threads\n- Implementing protocol conformances on MainActor-isolated types\n- Enabling Approachable Concurrency build settings in Xcode 26\n\n## Core Problem: Implicit Background Offloading\n\nIn Swift 6.1 and earlier, async functions could be implicitly offloaded to background threads, causing data-race errors even in seemingly safe code:\n\n```swift\n\u002F\u002F Swift 6.1: ERROR\n@MainActor\nfinal class StickerModel {\n    let photoProcessor = PhotoProcessor()\n\n    func extractSticker(_ item: PhotosPickerItem) async throws -> Sticker? {\n        guard let data = try await item.loadTransferable(type: Data.self) else { return nil }\n\n        \u002F\u002F Error: Sending 'self.photoProcessor' risks causing data races\n        return await photoProcessor.extractSticker(data: data, with: item.itemIdentifier)\n    }\n}\n```\n\nSwift 6.2 fixes this: async functions stay on the calling actor by default.\n\n```swift\n\u002F\u002F Swift 6.2: OK — async stays on MainActor, no data race\n@MainActor\nfinal class StickerModel {\n    let photoProcessor = PhotoProcessor()\n\n    func extractSticker(_ item: PhotosPickerItem) async throws -> Sticker? {\n        guard let data = try await item.loadTransferable(type: Data.self) else { return nil }\n        return await photoProcessor.extractSticker(data: data, with: item.itemIdentifier)\n    }\n}\n```\n\n## Core Pattern — Isolated Conformances\n\nMainActor types can now conform to non-isolated protocols safely:\n\n```swift\nprotocol Exportable {\n    func export()\n}\n\n\u002F\u002F Swift 6.1: ERROR — crosses into main actor-isolated code\n\u002F\u002F Swift 6.2: OK with isolated conformance\nextension StickerModel: @MainActor Exportable {\n    func export() {\n        photoProcessor.exportAsPNG()\n    }\n}\n```\n\nThe compiler ensures the conformance is only used on the main actor:\n\n```swift\n\u002F\u002F OK — ImageExporter is also @MainActor\n@MainActor\nstruct ImageExporter {\n    var items: [any Exportable]\n\n    mutating func add(_ item: StickerModel) {\n        items.append(item)  \u002F\u002F Safe: same actor isolation\n    }\n}\n\n\u002F\u002F ERROR — nonisolated context can't use MainActor conformance\nnonisolated struct ImageExporter {\n    var items: [any Exportable]\n\n    mutating func add(_ item: StickerModel) {\n        items.append(item)  \u002F\u002F Error: Main actor-isolated conformance cannot be used here\n    }\n}\n```\n\n## Core Pattern — Global and Static Variables\n\nProtect global\u002Fstatic state with MainActor:\n\n```swift\n\u002F\u002F Swift 6.1: ERROR — non-Sendable type may have shared mutable state\nfinal class StickerLibrary {\n    static let shared: StickerLibrary = .init()  \u002F\u002F Error\n}\n\n\u002F\u002F Fix: Annotate with @MainActor\n@MainActor\nfinal class StickerLibrary {\n    static let shared: StickerLibrary = .init()  \u002F\u002F OK\n}\n```\n\n### MainActor Default Inference Mode\n\nSwift 6.2 introduces a mode where MainActor is inferred by default — no manual annotations needed:\n\n```swift\n\u002F\u002F With MainActor default inference enabled:\nfinal class StickerLibrary {\n    static let shared: StickerLibrary = .init()  \u002F\u002F Implicitly @MainActor\n}\n\nfinal class StickerModel {\n    let photoProcessor: PhotoProcessor\n    var selection: [PhotosPickerItem]  \u002F\u002F Implicitly @MainActor\n}\n\nextension StickerModel: Exportable {  \u002F\u002F Implicitly @MainActor conformance\n    func export() {\n        photoProcessor.exportAsPNG()\n    }\n}\n```\n\nThis mode is opt-in and recommended for apps, scripts, and other executable targets.\n\n## Core Pattern — @concurrent for Background Work\n\nWhen you need actual parallelism, explicitly offload with `@concurrent`:\n\n> **Important:** This example requires Approachable Concurrency build settings — SE-0466 (MainActor default isolation) and SE-0461 (NonisolatedNonsendingByDefault). With these enabled, `extractSticker` stays on the caller's actor, making mutable state access safe. **Without these settings, this code has a data race** — the compiler will flag it.\n\n```swift\nnonisolated final class PhotoProcessor {\n    private var cachedStickers: [String: Sticker] = [:]\n\n    func extractSticker(data: Data, with id: String) async -> Sticker {\n        if let sticker = cachedStickers[id] {\n            return sticker\n        }\n\n        let sticker = await Self.extractSubject(from: data)\n        cachedStickers[id] = sticker\n        return sticker\n    }\n\n    \u002F\u002F Offload expensive work to concurrent thread pool\n    @concurrent\n    static func extractSubject(from data: Data) async -> Sticker { \u002F* ... *\u002F }\n}\n\n\u002F\u002F Callers must await\nlet processor = PhotoProcessor()\nprocessedPhotos[item.id] = await processor.extractSticker(data: data, with: item.id)\n```\n\nTo use `@concurrent`:\n1. Mark the containing type as `nonisolated`\n2. Add `@concurrent` to the function\n3. Add `async` if not already asynchronous\n4. Add `await` at call sites\n\n## Key Design Decisions\n\n| Decision | Rationale |\n|----------|-----------|\n| Single-threaded by default | Most natural code is data-race free; concurrency is opt-in |\n| Async stays on calling actor | Eliminates implicit offloading that caused data-race errors |\n| Isolated conformances | MainActor types can conform to protocols without unsafe workarounds |\n| `@concurrent` explicit opt-in | Background execution is a deliberate performance choice, not accidental |\n| MainActor default inference | Reduces boilerplate `@MainActor` annotations for app targets |\n| Opt-in adoption | Non-breaking migration path — enable features incrementally |\n\n## Migration Steps\n\n1. **Enable in Xcode**: Swift Compiler > Concurrency section in Build Settings\n2. **Enable in SPM**: Use `SwiftSettings` API in package manifest\n3. **Use migration tooling**: Automatic code changes via swift.org\u002Fmigration\n4. **Start with MainActor defaults**: Enable inference mode for app targets\n5. **Add `@concurrent` where needed**: Profile first, then offload hot paths\n6. **Test thoroughly**: Data-race issues become compile-time errors\n\n## Best Practices\n\n- **Start on MainActor** — write single-threaded code first, optimize later\n- **Use `@concurrent` only for CPU-intensive work** — image processing, compression, complex computation\n- **Enable MainActor inference mode** for app targets that are mostly single-threaded\n- **Profile before offloading** — use Instruments to find actual bottlenecks\n- **Protect globals with MainActor** — global\u002Fstatic mutable state needs actor isolation\n- **Use isolated conformances** instead of `nonisolated` workarounds or `@Sendable` wrappers\n- **Migrate incrementally** — enable features one at a time in build settings\n\n## Anti-Patterns to Avoid\n\n- Applying `@concurrent` to every async function (most don't need background execution)\n- Using `nonisolated` to suppress compiler errors without understanding isolation\n- Keeping legacy `DispatchQueue` patterns when actors provide the same safety\n- Skipping `model.availability` checks in concurrency-related Foundation Models code\n- Fighting the compiler — if it reports a data race, the code has a real concurrency issue\n- Assuming all async code runs in the background (Swift 6.2 default: stays on calling actor)\n\n## When to Use\n\n- All new Swift 6.2+ projects (Approachable Concurrency is the recommended default)\n- Migrating existing apps from Swift 5.x or 6.0\u002F6.1 concurrency\n- Resolving data-race safety compiler errors during Xcode 26 adoption\n- Building MainActor-centric app architectures (most UI apps)\n- Performance optimization — offloading specific heavy computations to background\n","# Swift 6.2 Approachable Concurrency\n\nPatterns for adopting Swift 6.2's concurrency model where code runs single-threaded by default and concurrency is introduced explicitly. Eliminates common data-race errors without sacrificing performance.\n\n## When to Activate\n\n- Migrating Swift 5.x or 6.0\u002F6.1 projects to Swift 6.2\n- Resolving data-race safety compiler errors\n- Designing MainActor-based app architecture\n- Offloading CPU-intensive work to background threads\n- Implementing protocol conformances on MainActor-isolated types\n- Enabling Approachable Concurrency build settings in Xcode 26\n\n## Core Problem: Implicit Background Offloading\n\nIn Swift 6.1 and earlier, async functions could be implicitly offloaded to background threads, causing data-race errors even in seemingly safe code:\n\n```swift\n\u002F\u002F Swift 6.1: ERROR\n@MainActor\nfinal class StickerModel {\n    let photoProcessor = PhotoProcessor()\n\n    func extractSticker(_ item: PhotosPickerItem) async throws -> Sticker? {\n        guard let data = try await item.loadTransferable(type: Data.self) else { return nil }\n\n        \u002F\u002F Error: Sending 'self.photoProcessor' risks causing data races\n        return await photoProcessor.extractSticker(data: data, with: item.itemIdentifier)\n    }\n}\n```\n\nSwift 6.2 fixes this: async functions stay on the calling actor by default.\n\n```swift\n\u002F\u002F Swift 6.2: OK — async stays on MainActor, no data race\n@MainActor\nfinal class StickerModel {\n    let photoProcessor = PhotoProcessor()\n\n    func extractSticker(_ item: PhotosPickerItem) async throws -> Sticker? {\n        guard let data = try await item.loadTransferable(type: Data.self) else { return nil }\n        return await photoProcessor.extractSticker(data: data, with: item.itemIdentifier)\n    }\n}\n```\n\n## Core Pattern — Isolated Conformances\n\nMainActor types can now conform to non-isolated protocols safely:\n\n```swift\nprotocol Exportable {\n    func export()\n}\n\n\u002F\u002F Swift 6.1: ERROR — crosses into main actor-isolated code\n\u002F\u002F Swift 6.2: OK with isolated conformance\nextension StickerModel: @MainActor Exportable {\n    func export() {\n        photoProcessor.exportAsPNG()\n    }\n}\n```\n\nThe compiler ensures the conformance is only used on the main actor:\n\n```swift\n\u002F\u002F OK — ImageExporter is also @MainActor\n@MainActor\nstruct ImageExporter {\n    var items: [any Exportable]\n\n    mutating func add(_ item: StickerModel) {\n        items.append(item)  \u002F\u002F Safe: same actor isolation\n    }\n}\n\n\u002F\u002F ERROR — nonisolated context can't use MainActor conformance\nnonisolated struct ImageExporter {\n    var items: [any Exportable]\n\n    mutating func add(_ item: StickerModel) {\n        items.append(item)  \u002F\u002F Error: Main actor-isolated conformance cannot be used here\n    }\n}\n```\n\n## Core Pattern — Global and Static Variables\n\nProtect global\u002Fstatic state with MainActor:\n\n```swift\n\u002F\u002F Swift 6.1: ERROR — non-Sendable type may have shared mutable state\nfinal class StickerLibrary {\n    static let shared: StickerLibrary = .init()  \u002F\u002F Error\n}\n\n\u002F\u002F Fix: Annotate with @MainActor\n@MainActor\nfinal class StickerLibrary {\n    static let shared: StickerLibrary = .init()  \u002F\u002F OK\n}\n```\n\n### MainActor Default Inference Mode\n\nSwift 6.2 introduces a mode where MainActor is inferred by default — no manual annotations needed:\n\n```swift\n\u002F\u002F With MainActor default inference enabled:\nfinal class StickerLibrary {\n    static let shared: StickerLibrary = .init()  \u002F\u002F Implicitly @MainActor\n}\n\nfinal class StickerModel {\n    let photoProcessor: PhotoProcessor\n    var selection: [PhotosPickerItem]  \u002F\u002F Implicitly @MainActor\n}\n\nextension StickerModel: Exportable {  \u002F\u002F Implicitly @MainActor conformance\n    func export() {\n        photoProcessor.exportAsPNG()\n    }\n}\n```\n\nThis mode is opt-in and recommended for apps, scripts, and other executable targets.\n\n## Core Pattern — @concurrent for Background Work\n\nWhen you need actual parallelism, explicitly offload with `@concurrent`:\n\n> **Important:** This example requires Approachable Concurrency build settings — SE-0466 (MainActor default isolation) and SE-0461 (NonisolatedNonsendingByDefault). With these enabled, `extractSticker` stays on the caller's actor, making mutable state access safe. **Without these settings, this code has a data race** — the compiler will flag it.\n\n```swift\nnonisolated final class PhotoProcessor {\n    private var cachedStickers: [String: Sticker] = [:]\n\n    func extractSticker(data: Data, with id: String) async -> Sticker {\n        if let sticker = cachedStickers[id] {\n            return sticker\n        }\n\n        let sticker = await Self.extractSubject(from: data)\n        cachedStickers[id] = sticker\n        return sticker\n    }\n\n    \u002F\u002F Offload expensive work to concurrent thread pool\n    @concurrent\n    static func extractSubject(from data: Data) async -> Sticker { \u002F* ... *\u002F }\n}\n\n\u002F\u002F Callers must await\nlet processor = PhotoProcessor()\nprocessedPhotos[item.id] = await processor.extractSticker(data: data, with: item.id)\n```\n\nTo use `@concurrent`:\n1. Mark the containing type as `nonisolated`\n2. Add `@concurrent` to the function\n3. Add `async` if not already asynchronous\n4. Add `await` at call sites\n\n## Key Design Decisions\n\n| Decision | Rationale |\n|----------|-----------|\n| Single-threaded by default | Most natural code is data-race free; concurrency is opt-in |\n| Async stays on calling actor | Eliminates implicit offloading that caused data-race errors |\n| Isolated conformances | MainActor types can conform to protocols without unsafe workarounds |\n| `@concurrent` explicit opt-in | Background execution is a deliberate performance choice, not accidental |\n| MainActor default inference | Reduces boilerplate `@MainActor` annotations for app targets |\n| Opt-in adoption | Non-breaking migration path — enable features incrementally |\n\n## Migration Steps\n\n1. **Enable in Xcode**: Swift Compiler > Concurrency section in Build Settings\n2. **Enable in SPM**: Use `SwiftSettings` API in package manifest\n3. **Use migration tooling**: Automatic code changes via swift.org\u002Fmigration\n4. **Start with MainActor defaults**: Enable inference mode for app targets\n5. **Add `@concurrent` where needed**: Profile first, then offload hot paths\n6. **Test thoroughly**: Data-race issues become compile-time errors\n\n## Best Practices\n\n- **Start on MainActor** — write single-threaded code first, optimize later\n- **Use `@concurrent` only for CPU-intensive work** — image processing, compression, complex computation\n- **Enable MainActor inference mode** for app targets that are mostly single-threaded\n- **Profile before offloading** — use Instruments to find actual bottlenecks\n- **Protect globals with MainActor** — global\u002Fstatic mutable state needs actor isolation\n- **Use isolated conformances** instead of `nonisolated` workarounds or `@Sendable` wrappers\n- **Migrate incrementally** — enable features one at a time in build settings\n\n## Anti-Patterns to Avoid\n\n- Applying `@concurrent` to every async function (most don't need background execution)\n- Using `nonisolated` to suppress compiler errors without understanding isolation\n- Keeping legacy `DispatchQueue` patterns when actors provide the same safety\n- Skipping `model.availability` checks in concurrency-related Foundation Models code\n- Fighting the compiler — if it reports a data race, the code has a real concurrency issue\n- Assuming all async code runs in the background (Swift 6.2 default: stays on calling actor)\n\n## When to Use\n\n- All new Swift 6.2+ projects (Approachable Concurrency is the recommended default)\n- Migrating existing apps from Swift 5.x or 6.0\u002F6.1 concurrency\n- Resolving data-race safety compiler errors during Xcode 26 adoption\n- Building MainActor-centric app architectures (most UI apps)\n- Performance optimization — offloading specific heavy computations to background\n",{"name":5,"description":7},"main","c9103dbad48ef3005f163584d0f2abd4591217f6","skills\u002Fecc-swift-concurrency-6-2",1,"https:\u002F\u002Fgithub.com\u002F503496348-ops\u002Fmischief-production","https:\u002F\u002Fgithub.com\u002F503496348-ops","https:\u002F\u002F503496348-ops.github.io\u002Fatomcollide-product-matrix\u002F#tree","元素碰撞-AtomCollide-AI 智能体实验室 测试人专属成长社群 正式招募\r\n我们的目标很纯粹：连接每一位测试工程师\u002FAI使用探索与爱好者，让你在这里既能扎实打磨技术硬实力，也能打通职业晋升的新通路，这是一个专注于AI领域的开源组","2026-07-30 00:35:42",{"source":8,"skillName":5,"commands":34,"prompt":44,"zipAvailable":45},[35,38,41],{"tool":36,"command":37},"npx","npx skills add 503496348-ops\u002Fmischief-production --skill swift-concurrency-6-2",{"tool":39,"command":40},"bunx","bunx skills add 503496348-ops\u002Fmischief-production --skill swift-concurrency-6-2",{"tool":42,"command":43},"pnpm","pnpm dlx skills add 503496348-ops\u002Fmischief-production --skill swift-concurrency-6-2","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002F503496348-ops\u002Fmischief-production\u002Fblob\u002Fmain\u002Fskills\u002Fecc-swift-concurrency-6-2\u002FSKILL.md",true,[],[48,55,62,69,76,83],{"skillNo":49,"name":50,"nameZh":6,"description":51,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":52,"categories":53,"keywords":54,"publishedAt":19},"01M77YG7NPZHE751W9QGK3H9ED","writing-skills","Use when creating new skills, editing existing skills, or verifying skills work before deployment","https:\u002F\u002Fgithub.com\u002F503496348-ops\u002Fmischief-production\u002Fblob\u002Fmain\u002Fskills\u002Fsp-writing-skills\u002FSKILL.md",[],[],{"skillNo":56,"name":57,"nameZh":6,"description":58,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":59,"categories":60,"keywords":61,"publishedAt":19},"01M77YG4HPYH0GJP974DZ6KCPQ","writing-plans","Use when you have a spec or requirements for a multi-step task, before touching code","https:\u002F\u002Fgithub.com\u002F503496348-ops\u002Fmischief-production\u002Fblob\u002Fmain\u002Fskills\u002Fsp-writing-plans\u002FSKILL.md",[],[],{"skillNo":63,"name":64,"nameZh":6,"description":65,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":66,"categories":67,"keywords":68,"publishedAt":19},"01M77YFZW1FZ1GVC5C89NPE5M8","verification-before-completion","Use when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always","https:\u002F\u002Fgithub.com\u002F503496348-ops\u002Fmischief-production\u002Fblob\u002Fmain\u002Fskills\u002Fsp-verification-before-completion\u002FSKILL.md",[],[],{"skillNo":70,"name":71,"nameZh":6,"description":72,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":73,"categories":74,"keywords":75,"publishedAt":19},"01M77YFVPWANT5VE5GWBTKHPA2","using-智械工程","Use when starting any conversation - establishes how to find and use skills, requiring skill invocation before ANY response including clarifying questions","https:\u002F\u002Fgithub.com\u002F503496348-ops\u002Fmischief-production\u002Fblob\u002Fmain\u002Fskills\u002Fsp-using-superpowers\u002FSKILL.md",[],[],{"skillNo":77,"name":78,"nameZh":6,"description":79,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":80,"categories":81,"keywords":82,"publishedAt":19},"01M77YFQJAW5PX3QYSBCD3B24S","using-git-worktrees","Use when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallback","https:\u002F\u002Fgithub.com\u002F503496348-ops\u002Fmischief-production\u002Fblob\u002Fmain\u002Fskills\u002Fsp-using-git-worktrees\u002FSKILL.md",[],[],{"skillNo":84,"name":85,"nameZh":6,"description":86,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":87,"categories":88,"keywords":89,"publishedAt":19},"01M77YFMSTB70VX8W2QHNJWYB0","test-driven-development","Use when implementing any feature or bugfix, before writing implementation code","https:\u002F\u002Fgithub.com\u002F503496348-ops\u002Fmischief-production\u002Fblob\u002Fmain\u002Fskills\u002Fsp-test-driven-development\u002FSKILL.md",[],[]]