Swift API Style Workflow
Purpose
Make Swift APIs feel Swifty, ergonomic, intuitive, and human-friendly at the call site.
This skill owns language-level API style. Hand off to apple-dev-skills for Apple framework or Xcode project behavior, and to server-side-swift for Vapor, Hummingbird, SwiftNIO, deployment, persistence, observability, or auth behavior.
Source Check
Use repo-local guidance first. When general Swift API behavior needs a source, prefer the official Swift API Design Guidelines and current Swift documentation before community style guides.
Workflow
- Inspect the current API surface:
- public and internal symbols
- call sites
- result and error shapes
- overloads, default arguments, and options structs
- access control
- naming consistency across sibling APIs
- Classify the work:
- new API design
- API cleanup
- call-site ergonomics review
- error and result-shape repair
- access-control tightening
- Optimize for the caller:
- prefer names that read naturally at the use site
- keep labels meaningful instead of decorative
- prefer domain values over ambiguous tuples, dictionaries, or strings
- prefer defaulted parameters for small option sets
- prefer request or options structs when public APIs reach four or more meaningful parameters
- prefer enum-backed choices over boolean soups or stringly-typed modes
- Tighten result and failure behavior:
- use
throws, typed domain errors, Result, or optional returns according to caller recovery needs
- hand deeper failure-shape design to
swift-error-handling-style-workflow
- make invalid states hard to construct
- include operation, source, likely cause, and next inspection point in operator-facing errors and logs
- Remove accidental API weight:
- collapse needless overloads
- remove compatibility shims unless explicitly approved
- replace broad managers with small support types when the current type owns unrelated jobs
- keep dependency injection unidirectional and data flow straight
Style Defaults
- Prefer compact Swifty syntax when it is obvious.
- Prefer trailing closures, key paths, shorthand closure arguments, and fluent calls when they improve readability.
- Prefer named intermediate values when a chain needs a diagnostic boundary or the next reader would have to mentally execute it.
- Prefer small composable values, functions, and extensions over stateful orchestration types.
- Prefer complete cleanup passes over leaving duplicate long-term APIs behind.
Output Shape
Return:
API state: the current shape and main pain points.
Recommended surface: the target symbols, names, labels, and result shape.
Call-site examples: compact examples showing the intended feel.
Migration: compatibility impact and whether shims are being avoided or deliberately approved.
Validation: compile, test, or review checks needed.
Guardrails
- Do not rename public APIs casually when the repo has release or compatibility constraints.
- Do not add wrappers, managers, or service layers without a concrete near-term use case.
- Do not expand readable fluent Swift into verbose ceremony just to satisfy a generic style guide.
- Do not hide recoverable errors in logs or
nil when the caller can do something useful.
- Do not keep duplicate old and new paths unless Gale explicitly approves that compromise.
1---2name: swift-api-style-workflow3description: Review, design, or repair Swift APIs for Swifty naming, call-site ergonomics, access control, typed result shapes, human-friendly errors, and consistency across sibling symbols. Use swift-error-handling-style-workflow for deeper failure-shape decisions.4license: Apache-2.05---67# Swift API Style Workflow89## Purpose1011Make Swift APIs feel Swifty, ergonomic, intuitive, and human-friendly at the call site.1213This skill owns language-level API style. Hand off to `apple-dev-skills` for Apple framework or Xcode project behavior, and to `server-side-swift` for Vapor, Hummingbird, SwiftNIO, deployment, persistence, observability, or auth behavior.1415## Source Check1617Use repo-local guidance first. When general Swift API behavior needs a source, prefer the official Swift API Design Guidelines and current Swift documentation before community style guides.1819## Workflow20211. Inspect the current API surface:22 - public and internal symbols23 - call sites24 - result and error shapes25 - overloads, default arguments, and options structs26 - access control27 - naming consistency across sibling APIs282. Classify the work:29 - new API design30 - API cleanup31 - call-site ergonomics review32 - error and result-shape repair33 - access-control tightening343. Optimize for the caller:35 - prefer names that read naturally at the use site36 - keep labels meaningful instead of decorative37 - prefer domain values over ambiguous tuples, dictionaries, or strings38 - prefer defaulted parameters for small option sets39 - prefer request or options structs when public APIs reach four or more meaningful parameters40 - prefer enum-backed choices over boolean soups or stringly-typed modes414. Tighten result and failure behavior:42 - use `throws`, typed domain errors, `Result`, or optional returns according to caller recovery needs43 - hand deeper failure-shape design to `swift-error-handling-style-workflow`44 - make invalid states hard to construct45 - include operation, source, likely cause, and next inspection point in operator-facing errors and logs465. Remove accidental API weight:47 - collapse needless overloads48 - remove compatibility shims unless explicitly approved49 - replace broad managers with small support types when the current type owns unrelated jobs50 - keep dependency injection unidirectional and data flow straight5152## Style Defaults5354- Prefer compact Swifty syntax when it is obvious.55- Prefer trailing closures, key paths, shorthand closure arguments, and fluent calls when they improve readability.56- Prefer named intermediate values when a chain needs a diagnostic boundary or the next reader would have to mentally execute it.57- Prefer small composable values, functions, and extensions over stateful orchestration types.58- Prefer complete cleanup passes over leaving duplicate long-term APIs behind.5960## Output Shape6162Return:63641. `API state`: the current shape and main pain points.652. `Recommended surface`: the target symbols, names, labels, and result shape.663. `Call-site examples`: compact examples showing the intended feel.674. `Migration`: compatibility impact and whether shims are being avoided or deliberately approved.685. `Validation`: compile, test, or review checks needed.6970## Guardrails7172- Do not rename public APIs casually when the repo has release or compatibility constraints.73- Do not add wrappers, managers, or service layers without a concrete near-term use case.74- Do not expand readable fluent Swift into verbose ceremony just to satisfy a generic style guide.75- Do not hide recoverable errors in logs or `nil` when the caller can do something useful.76- Do not keep duplicate old and new paths unless Gale explicitly approves that compromise.