mirror of
https://github.com/Dimillian/Skills.git
synced 2026-03-25 08:55:54 +00:00
Hullo @dimillian 👋 I ran your skills through `tessl skill review` at work and found some targeted improvements. Here's the before/after: | Skill | Before | After | Change | |-------|--------|-------|--------| | swiftui-ui-patterns | 81% | 100% | +19% | | github | 85% | 100% | +15% | | macos-spm-app-packaging | 86% | 100% | +14% | | react-component-performance | 86% | 100% | +14% | | swift-concurrency-expert | 88% | 100% | +12% | | app-store-changelog | 93% | 100% | +7% | | ios-debugger-agent | 94% | 100% | +6% | | swiftui-view-refactor | 93% | 95% | +2% | | swiftui-liquid-glass | 100% | 100% | — | | swiftui-performance-audit | 100% | 100% | — | <details> <summary>Changes made</summary> **swiftui-ui-patterns** — Expanded description with additional trigger terms (VStack/HStack, @State, @Binding, navigation hierarchies, custom view modifiers). Added explicit build validation checkpoints and error recovery guidance to the workflow steps. **github** — Added explicit "Use when..." clause with natural trigger terms (check CI status, create PR, list issues). Added a structured "Debugging a CI Failure" numbered workflow organizing existing commands into a clear investigation sequence. **macos-spm-app-packaging** — Added a minimum end-to-end example (bootstrap to running app). Added validation checkpoints after packaging, signing, and notarization with specific verification commands (codesign, spctl, stapler). Added a common notarization failures troubleshooting table. **react-component-performance** — Added three concrete before/after code examples (isolate ticking state, stabilize callbacks with useCallback + memo, derived data with useMemo). Expanded profiling validation with explicit React DevTools Profiler steps. **swift-concurrency-expert** — Expanded description with concrete actions (adding Sendable conformance, @MainActor annotations, resolving actor isolation warnings). Added verification step to workflow. Added three before/after Swift code examples covering @MainActor, protocol conformance isolation, and @concurrent. **app-store-changelog** — Added commit-to-bullet transformation examples showing how raw commits map to user-facing App Store bullets, plus examples of internal-only commits that get dropped. Added a complete example "What's New" output block. **ios-debugger-agent** — Added build failure handling and post-launch verification checkpoints to the core workflow (verify app launched via describe_ui or screenshot before proceeding to UI interaction). **swiftui-view-refactor** — Tightened prose in sections 3, 3b, and large-view handling. Removed a redundant example. Converted workflow list to clean numbered format. </details> Honest disclosure — I work at @tesslio where we build tooling around skills like these. Not a pitch - just saw room for improvement and wanted to contribute. If you want to run reviews, evals and optimizations yourself, just `npm install @tessl/cli` then run `tessl skill review path/to/your/SKILL.md`, and click here (https://tessl.io/registry/skills/submit) to find out more. Thanks in advance 🙏
105 lines
4.2 KiB
Markdown
105 lines
4.2 KiB
Markdown
---
|
|
name: swift-concurrency-expert
|
|
description: Swift Concurrency review and remediation for Swift 6.2+. Use when asked to review Swift Concurrency usage, improve concurrency compliance, or fix Swift concurrency compiler errors in a feature or file. Concrete actions include adding Sendable conformance, applying @MainActor annotations, resolving actor isolation warnings, fixing data race diagnostics, and migrating completion handlers to async/await.
|
|
---
|
|
|
|
# Swift Concurrency Expert
|
|
|
|
## Overview
|
|
|
|
Review and fix Swift Concurrency issues in Swift 6.2+ codebases by applying actor isolation, Sendable safety, and modern concurrency patterns with minimal behavior changes.
|
|
|
|
## Workflow
|
|
|
|
### 1. Triage the issue
|
|
|
|
- Capture the exact compiler diagnostics and the offending symbol(s).
|
|
- Check project concurrency settings: Swift language version (6.2+), strict concurrency level, and whether approachable concurrency (default actor isolation / main-actor-by-default) is enabled.
|
|
- Identify the current actor context (`@MainActor`, `actor`, `nonisolated`) and whether a default actor isolation mode is enabled.
|
|
- Confirm whether the code is UI-bound or intended to run off the main actor.
|
|
|
|
### 2. Apply the smallest safe fix
|
|
|
|
Prefer edits that preserve existing behavior while satisfying data-race safety.
|
|
|
|
Common fixes:
|
|
- **UI-bound types**: annotate the type or relevant members with `@MainActor`.
|
|
- **Protocol conformance on main actor types**: make the conformance isolated (e.g., `extension Foo: @MainActor SomeProtocol`).
|
|
- **Global/static state**: protect with `@MainActor` or move into an actor.
|
|
- **Background work**: move expensive work into a `@concurrent` async function on a `nonisolated` type or use an `actor` to guard mutable state.
|
|
- **Sendable errors**: prefer immutable/value types; add `Sendable` conformance only when correct; avoid `@unchecked Sendable` unless you can prove thread safety.
|
|
|
|
### 3. Verify the fix
|
|
|
|
- Rebuild and confirm all concurrency diagnostics are resolved with no new warnings introduced.
|
|
- Run the test suite to check for regressions — concurrency changes can introduce subtle runtime issues even when the build is clean.
|
|
- 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.
|
|
|
|
### Examples
|
|
|
|
**UI-bound type — adding `@MainActor`**
|
|
|
|
```swift
|
|
// Before: data-race warning because ViewModel is accessed from the main thread
|
|
// but has no actor isolation
|
|
class ViewModel: ObservableObject {
|
|
@Published var title: String = ""
|
|
func load() { title = "Loaded" }
|
|
}
|
|
|
|
// After: annotate the whole type so all stored state and methods are
|
|
// automatically isolated to the main actor
|
|
@MainActor
|
|
class ViewModel: ObservableObject {
|
|
@Published var title: String = ""
|
|
func load() { title = "Loaded" }
|
|
}
|
|
```
|
|
|
|
**Protocol conformance isolation**
|
|
|
|
```swift
|
|
// Before: compiler error — SomeProtocol method is nonisolated but the
|
|
// conforming type is @MainActor
|
|
@MainActor
|
|
class Foo: SomeProtocol {
|
|
func protocolMethod() { /* accesses main-actor state */ }
|
|
}
|
|
|
|
// After: scope the conformance to @MainActor so the requirement is
|
|
// satisfied inside the correct isolation context
|
|
@MainActor
|
|
extension Foo: SomeProtocol {
|
|
func protocolMethod() { /* safely accesses main-actor state */ }
|
|
}
|
|
```
|
|
|
|
**Background work with `@concurrent`**
|
|
|
|
```swift
|
|
// Before: expensive computation blocks the main actor
|
|
@MainActor
|
|
func processData(_ input: [Int]) -> [Int] {
|
|
input.map { heavyTransform($0) } // runs on main thread
|
|
}
|
|
|
|
// After: hop off the main actor for the heavy work, then return the result
|
|
// The caller awaits the result and stays on its own actor
|
|
nonisolated func processData(_ input: [Int]) async -> [Int] {
|
|
await Task.detached(priority: .userInitiated) {
|
|
input.map { heavyTransform($0) }
|
|
}.value
|
|
}
|
|
|
|
// Or, using a @concurrent async function (Swift 6.2+):
|
|
@concurrent
|
|
func processData(_ input: [Int]) async -> [Int] {
|
|
input.map { heavyTransform($0) }
|
|
}
|
|
```
|
|
|
|
## Reference material
|
|
|
|
- See `references/swift-6-2-concurrency.md` for Swift 6.2 changes, patterns, and examples.
|
|
- See `references/approachable-concurrency.md` when the project is opted into approachable concurrency mode.
|
|
- See `references/swiftui-concurrency-tour-wwdc.md` for SwiftUI-specific concurrency guidance.
|