1---2name: swift-api-design-guidelines-skill3description: Write, review, or improve Swift APIs using Swift API Design Guidelines for naming, argument labels, documentation comments, terminology, and general conventions. Use when designing new APIs, refactoring existing interfaces, or reviewing API clarity and fluency.4---5
6# Swift API Design Guidelines Skill
7
8## Overview
9Use this skill to design and review Swift APIs that are clear at the point of use, fluent in call sites, and aligned with established Swift naming and labeling conventions. Prioritize readability, explicit intent, and consistency across declarations, call sites, and documentation comments.
10
11## Work Decision Tree
12
13### 1) Review existing code
14- Inspect declarations and call sites together, not declarations alone.
15- Check naming clarity and fluency (see `references/promote-clear-usage.md`, `references/strive-for-fluent-usage.md`).
16- Check argument labels and parameter naming (see `references/parameters.md`, `references/argument-labels.md`).
17- Check documentation comments and symbol markup (see `references/fundamentals.md`).
18- Check conventions and overload safety (see `references/general-conventions.md`, `references/special-instructions.md`).
19
20### 2) Improve existing code
21- Rename APIs that are ambiguous, redundant, or role-unclear.
22- Refactor labels to improve grammatical call-site reading.
23- Replace weakly named parameters with role-based names.
24- Resolve overload sets that become ambiguous with weak typing.
25- Strengthen documentation summaries to describe behavior and returns precisely.
26
27### 3) Implement new feature
28- Start from use-site examples before finalizing declarations.
29- Choose base names and labels so calls read as clear English phrases.
30- Add defaults only when they simplify common usage.
31- Define mutating/nonmutating pairs with consistent naming.
32- Add concise documentation comments for every new declaration.
33
34## Core Guidelines
35
36### Fundamentals
37- Clarity at the point of use is the top priority.
38- Clarity is more important than brevity.
39- Every declaration should have a documentation comment.
40- Summaries should state what the declaration does, returns, accesses, creates, or is.
41- Use recognized Swift symbol markup (`Parameter`, `Returns`, `Throws`, `Note`, etc.).
42
43### Promote Clear Usage
44- Include all words needed to avoid ambiguity.
45- Omit needless words, especially type repetition.
46- Name parameters and associated types by role, not type.
47- Add role nouns when type information is weak (`Any`, `NSObject`, `String`, `Int`).
48
49### Strive For Fluent Usage
50- Prefer method names that produce grammatical, readable call sites.
51- Start factory methods with `make`.
52- Name side-effect-free APIs as noun phrases; side-effecting APIs as imperative verbs.
53- Keep mutating/nonmutating naming pairs consistent (`sort`/`sorted`, `formUnion`/`union`).
54- Boolean APIs should read as assertions (`isEmpty`, `intersects`).
55
56### Use Terminology Well
57- Prefer common words unless terms of art are necessary for precision.
58- If using a term of art, preserve its established meaning.
59- Avoid non-standard abbreviations.
60- Embrace established domain precedent when it improves shared understanding.
61
62### Conventions, Parameters, And Labels
63- Document complexity for computed properties that are not `O(1)`.
64- Prefer methods/properties to free functions except special cases.
65- Follow Swift casing conventions, including acronym handling.
66- Use parameter names that improve generated documentation readability.
67- Prefer default arguments over method families when semantics are shared.
68- Place defaulted parameters near the end.
69- Apply argument labels based on grammar and meaning, not style preference.
70
71### Special Instructions
72- Label tuple members and name closure parameters in public API surfaces.
73- Be explicit with unconstrained polymorphism to avoid overload ambiguity.
74- Align names with semantics shown in documentation comments.
75
76## Quick Reference
77
78### Name Shape
79| Situation | Preferred Pattern |
80| --- | --- |
81| Mutating verb | `reverse()` |
82| Nonmutating verb | `reversed()` / `strippingNewlines()` |
83| Nonmutating noun op | `union(_:)` |
84| Mutating noun op | `formUnion(_:)` |
85| Factory method | `makeWidget(...)` |
86| Boolean query | `isEmpty`, `intersects(_:)` |
87
88### Argument Label Rules
89| Situation | Rule |
90| --- | --- |
91| Distinguishable unlabeled args | Omit labels only if distinction is still clear |
92| Value-preserving conversion init | Omit first label |
93| First arg in prepositional phrase | Usually label from the preposition |
94| First arg in grammatical phrase | Omit first label |
95| Defaulted arguments | Keep labels (they may be omitted at call sites) |
96| All other arguments | Label them |
97
98### Documentation Rules
99| Declaration Kind | Summary Should Describe |
100| --- | --- |
101| Function / method | What it does and what it returns |
102| Subscript | What it accesses |
103| Initializer | What it creates |
104| Other declarations | What it is |
105
106## Review Checklist
107
108### Clarity And Fluency
109- [ ] Call sites are clear without reading implementation details.
110- [ ] Base names include all words needed to remove ambiguity.
111- [ ] Names are concise and avoid repeating type names.
112- [ ] Calls read naturally and grammatically where it matters most.
113
114### Naming Semantics
115- [ ] Side-effect-free APIs read as nouns/queries.
116- [ ] Side-effecting APIs read as imperative verbs.
117- [ ] Mutating/nonmutating pairs use consistent naming patterns.
118- [ ] Boolean APIs read as assertions.
119
120### Parameters And Labels
121- [ ] Parameter names improve docs and role clarity.
122- [ ] Default parameters simplify common usage.
123- [ ] Defaulted parameters are near the end.
124- [ ] First argument labels follow grammar and conversion rules.
125- [ ] Remaining arguments are labeled unless omission is clearly justified.
126
127### Documentation And Conventions
128- [ ] Every declaration has a useful summary comment.
129- [ ] Symbol markup is used where appropriate.
130- [ ] Non-`O(1)` computed property complexity is documented.
131- [ ] Case conventions and acronym casing follow Swift norms.
132- [ ] Overloads avoid return-type-only distinctions and weak-type ambiguities.
133
134## References
135- `references/fundamentals.md` - Core principles and documentation comment rules
136- `references/promote-clear-usage.md` - Ambiguity reduction and role-based naming
137- `references/strive-for-fluent-usage.md` - Fluency, side effects, and mutating pairs
138- `references/use-terminology-well.md` - Terms of art, abbreviations, and precedent
139- `references/general-conventions.md` - Complexity docs, free function exceptions, casing, overloads
140- `references/parameters.md` - Parameter naming and default argument strategy
141- `references/argument-labels.md` - First-argument and general label rules
142- `references/special-instructions.md` - Tuple/closure naming and unconstrained polymorphism
143
144## Philosophy
145- Prefer clear use-site semantics over declaration cleverness.
146- Follow established Swift conventions before inventing local style rules.
147- Optimize for maintainability and reviewability of public API surfaces.
148- Keep guidance practical: apply the smallest change that improves clarity.