[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7F5SEH2F53VEDB4REVMB15Z":3,"skill-same:01M7F5SEH2F53VEDB4REVMB15Z":46},{"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":6,"ownerDescription":30,"updatedAt":31,"install":32,"resources":45},"01M7F5SEH2F53VEDB4REVMB15Z","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.","lza6\u002FArmor-piercing-system-prompts","lza6","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F128880206?v=4","01M7EB3K7WPX5T28EJ2NVHE6EG","Chinese-tingfeng","01M7EB3K97E1KQ16QWKJMFNGX8",11,"MIT","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F05-技能与代理开发\u002Fswift-concurrency-6-2\u002FSKILL.md",[],[],"2026-11-16 10:05:34",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","d69096e239f2a89aabc2cd078c47664a9d3b1e11","05-技能与代理开发\u002Fswift-concurrency-6-2",3,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts","https:\u002F\u002Fgithub.com\u002Flza6","个人vx：Tf00798\r\n个人✈：@TFGY999","2026-10-08 14:29:22",{"source":8,"skillName":5,"commands":33,"prompt":43,"zipAvailable":44},[34,37,40],{"tool":35,"command":36},"npx","npx skills add lza6\u002FArmor-piercing-system-prompts --skill swift-concurrency-6-2",{"tool":38,"command":39},"bunx","bunx skills add lza6\u002FArmor-piercing-system-prompts --skill swift-concurrency-6-2",{"tool":41,"command":42},"pnpm","pnpm dlx skills add lza6\u002FArmor-piercing-system-prompts --skill swift-concurrency-6-2","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F05-技能与代理开发\u002Fswift-concurrency-6-2\u002FSKILL.md",true,[],[47,54,59,66,73,80],{"skillNo":48,"name":49,"nameZh":6,"description":50,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":51,"categories":52,"keywords":53,"publishedAt":19},"01M7FFG485KY83TD6HSC4YPCMC","obsidian-clipper-template-creator","Guide for creating templates for the Obsidian Web Clipper. Use when you want to create a new clipping template, understand available variables, or format clipped content.","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobsidian-clipper-template-creator\u002FSKILL.md",[],[],{"skillNo":55,"name":49,"nameZh":6,"description":50,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":56,"categories":57,"keywords":58,"publishedAt":19},"01M7FFG0T6AZ0STEJPSB3CX84K","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobsidian-clipper-template-creator-antigravity-awesome-skills-main\u002FSKILL.md",[],[],{"skillNo":60,"name":61,"nameZh":6,"description":62,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":63,"categories":64,"keywords":65,"publishedAt":19},"01M7FFFY0QEM14SKWPDYGMXM2P","python-api","Programmatic Object-Detection-Metrics API guidance for BoundingBox, BoundingBoxes, Evaluator, enums, coordinate conversion, AP\u002FmAP semantics, and source-style import diagnostics.","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobject-detection-metrics\u002Fsub-skills\u002Fpython-api\u002FSKILL.md",[],[],{"skillNo":67,"name":68,"nameZh":6,"description":69,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":70,"categories":71,"keywords":72,"publishedAt":19},"01M7FFFVZQZ2GJ0C0TGP7JHD20","file-evaluation","Folder-based PASCAL VOC AP\u002FmAP evaluation from ground-truth and detection text files.","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobject-detection-metrics\u002Fsub-skills\u002Ffile-evaluation\u002FSKILL.md",[],[],{"skillNo":74,"name":75,"nameZh":6,"description":76,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":77,"categories":78,"keywords":79,"publishedAt":19},"01M7FFFSFNYSE77SJ6PE1CK2DA","object-detection-metrics","Guides legacy Object-Detection-Metrics PASCAL VOC AP\u002FmAP evaluation from detection text folders and direct Python API classes.","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobject-detection-metrics\u002FSKILL.md",[],[],{"skillNo":81,"name":82,"nameZh":6,"description":83,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":84,"categories":85,"keywords":86,"publishedAt":19},"01M7FFFP0GCK1RVXBCPQ8APBMT","nx-workspace-patterns","Configure and optimize Nx monorepo workspaces. Use when setting up Nx, configuring project boundaries, optimizing build caching, or implementing affected commands.","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fnx-workspace-patterns\u002FSKILL.md",[],[]]