Token导航 LogoToken导航TokenDH.com
开发规范需要联网github未标认证来源可访问许可证需确认审计通过

swift-api-design-guidelinesSwift API 设计 guidelines

Agent Skill

用于辅助 API 设计、接口文档、请求响应结构和服务集成说明。它适合让 Agent 梳理 endpoint、生成 OpenAPI 草稿、检查字段命名、整理错误码或辅助前后端联调。使用时需要确认真实业务语义、鉴权方式、分页和错误处理规则;涉及生成接口文档时,应避免凭空补字段,最好从现有代码、schema 或接口样例中提取事实。

总安装

3,504

周安装

146

GitHub Stars

470

下载量

1,168
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:swift-api-design-guidelines(Swift API 设计 guidelines)
来源仓库:https://github.com/dpearson2699/swift-ios-skills
仓库路径:skills/swift-api-design-guidelines
安装命令:
npx skills add https://github.com/dpearson2699/swift-ios-skills --skill swift-api-design-guidelines
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/dpearson2699/swift-ios-skills --skill swift-api-design-guidelines

简介

swift-api-design-guidelines 用于辅助 API 设计、接口文档和服务集成说明。

  • 可梳理 endpoint、生成 OpenAPI 草稿、检查字段命名和整理错误码。
  • 需确认真实业务语义、鉴权方式、分页和错误处理规则。
  • 涉及生成接口文档时应避免凭空补字段,最好从现有代码或样例中提取事实。
  • 适合前后端联调和接口规范制定场景。

SKILL.md

Swift API Design Guidelines

Apply the Swift API Design Guidelines when naming types, methods, properties, parameters, and argument labels. Targets Swift 6.3. For language features and syntax, see swift-language. For concurrency patterns, see swift-concurrency.

Contents

Argument Label Rules

Argument labels determine how a call site reads. Apply these rules in order.

When to omit the first argument label

Grammatical phrase rule. When the first argument forms a grammatical phrase with the base name, omit the label. Move any leading words from what would be the label into the base name instead.

// GOOD — reads as "add subview y"
view.addSubview(y)

// BAD — redundant label breaks the phrase
view.add(subview: y)

Value-preserving type conversions. When an initializer performs a value-preserving (widening) conversion, omit the first argument label.

// GOOD — widening conversion, no label
let value = Int64(someUInt32)
let str = String(someCharacter)

// Narrowing or lossy conversions keep a label
let approx = Int64(truncating: someDecimal)
let str = String(describing: someObject)

Indistinguishable arguments. When all arguments cannot be usefully distinguished, omit all labels.

// GOOD — arguments are peers
let smaller = min(x, y)
zip(sequence1, sequence2)

When to use a prepositional label

Prepositional phrase rule. When the first argument completes a prepositional phrase with the base name, label it with the preposition.

// GOOD — "remove boxes having length 12"
x.removeBoxes(havingLength: 12)

// GOOD — "fade from red"
view.fade(from: red)

// GOOD — "relative path from root"
path.relativePath(from: root)

Exception — abstraction boundary. When the first two arguments represent parts of a single abstraction, fold the preposition into the base name so each component gets its own label.

// GOOD — x and y are parts of a single abstraction (a point)
a.moveTo(x: b, y: c)

// BAD — preposition attaches to first arg, leaving y unlabeled
a.move(toX: b, y: c)

Default: label everything else

When no special rule above applies, label the argument.

// GOOD
array.split(maxSplits: 2)
button.setTitle("OK", for: .normal)
controller.dismiss(animated: true)
array.sorted(by: >)

Argument label decision table

SituationRuleExample
First arg completes grammatical phraseOmit label, merge words into base nameaddSubview(y)
Value-preserving init conversionOmit first labelInt64(someUInt32)
Arguments are indistinguishable peersOmit all labelsmin(x, y)
First arg completes prepositional phraseLabel with prepositionfade(from: red)
First two args form a single abstractionFold preposition into base namemoveTo(x: b, y: c)
Everything elseLabel itsplit(maxSplits: 2)

For extended examples and edge cases, see references/argument-labels-and-parameters.md.

Side-Effect Naming

Name functions and methods by their side effects.

Functions with side effects — imperative verbs

When a function mutates state, name it as an imperative verb phrase.

// Mutates — imperative verb
array.sort()
array.append(newElement)
list.remove(at: index)
timer.invalidate()

Functions without side effects — nouns or adjective phrases

When a function returns a result without mutating anything, name it as a noun phrase, adjective phrase, or read as a description of what it returns.

// Pure — noun/description
let d = point.distance(to: origin)
let area = rect.intersection(other)
let line = text.trimmingCharacters(in: .whitespaces)

Boolean properties and methods

Boolean properties and methods read as assertions about the receiver.

// GOOD — reads as "line is empty"
line.isEmpty
set.contains(element)
url.isFileURL

// BAD — not an assertion
line.empty       // verb? adjective?
set.includes     // incomplete phrase

For more examples, see references/side-effects-and-mutating-pairs.md.

Mutating and Nonmutating Pairs

When an operation has both mutating and nonmutating variants, name them as a pair.

Verb-described operations — -ed/-ing suffix

When the operation is naturally described by a verb:

  • Mutating: imperative verb (sort, append, reverse)
  • Nonmutating: past participle -ed or present participle -ing

Default to -ed (past participle). When -ed is ungrammatical — typically when the verb does not form a natural past participle, or when adding -ed produces an awkward phrase — use -ing (present participle) instead.

MutatingNonmutatingWhy
sort()sorted()-ed — "a sorted array"
reverse()reversed()-ed — "a reversed collection"
append(y)appending(y)-ing — "appended" is ungrammatical here
stripNewlines()strippingNewlines()-ing — "stripped newlines" is awkward

Noun-described operations — form- prefix

When the operation is naturally described by a noun:

  • Nonmutating: the noun itself (union, intersection)
  • Mutating: form prefix (formUnion, formIntersection)
// Nonmutating — returns new value
let combined = a.union(b)

// Mutating — modifies in place
a.formUnion(b)

Factory methods — make- prefix

Factory methods that create a new value start with make.

let iterator = collection.makeIterator()
let buffer = parser.makeBuffer()

Pair decision table

Operation described byMutating nameNonmutating nameExample pair
Verb (default)verbverb + -edsort() / sorted()
Verb (-ed is ungrammatical)verbverb + -ingstripNewlines() / strippingNewlines()
Nounform + NounnounformUnion(b) / union(b)

For the full -ed/-ing decision tree and stdlib examples, see references/side-effects-and-mutating-pairs.md.

Documentation Comments

Every public declaration must have a documentation comment.

Summary rules by declaration kind

DeclarationSummary describes
Function / methodWhat it does and what it returns
SubscriptWhat it accesses
InitializerWhat it creates
Type / property / variableWhat it is

Write summaries as a single sentence fragment, beginning with a verb (for actions) or a noun phrase (for entities), ending in a period.

/// Returns the element at the specified index.
func element(at index: Int) -> Element { ... }

/// The number of elements in the collection.
var count: Int { ... }

/// Creates a new array with the given elements.
init(_ elements: some Sequence<Element>) { ... }

/// Accesses the element at the specified position.
subscript(index: Int) -> Element { ... }

Symbol markup

Use standard symbol markup after the summary when relevant:

  • - Parameter name: for individual parameters
  • - Parameters: block for multiple parameters
  • - Returns: for the return value
  • - Throws: for errors thrown
  • - Complexity: for algorithmic complexity
/// Removes and returns the element at the specified position.
///
/// - Parameter index: The position of the element to remove.
/// - Returns: The removed element.
/// - Complexity: O(*n*), where *n* is the length of the collection.
mutating func remove(at index: Int) -> Element { ... }

O(1) complexity rule

Document the complexity of any computed property that is not O(1). Callers assume properties are O(1) by default. If a property does more than constant-time work, state the complexity explicitly.

/// The total weight of all items.
///
/// - Complexity: O(*n*), where *n* is the number of items.
var totalWeight: Double {
    items.reduce(0) { $0 + $1.weight }
}

For documentation patterns and examples, see references/conventions-and-special-rules.md.

Clarity and Naming

Clarity at the point of use is the most important goal. Every design decision serves the person reading a call site.

Clarity over brevity. Longer names are acceptable when they remove ambiguity. Do not abbreviate.

// GOOD
employees.remove(at: position)

// BAD — ambiguous: remove the element? remove at position?
employees.remove(position)

Include words needed to avoid ambiguity. If omitting a word makes the call site unclear, keep it.

// GOOD — "at" clarifies the argument's role
friends.remove(at: index)

// BAD — is "index" the element to remove or the position?
friends.remove(index)

Omit needless words. Do not repeat type information already available from the context.

// GOOD
allViews.remove(cancelButton)

// BAD — "Element" repeats the type
allViews.removeElement(cancelButton)

Name variables and parameters by role, not type. Use the entity's role in the current context, not its type name.

// GOOD — describes the role
var greeting: String
func add(_ observer: NSObject, for keyPath: String)

// BAD — names the type
var string: String
func add(_ object: NSObject, for string: String)

Compensate for weak type information. When a parameter type is Any, AnyObject, or a fundamental type like Int or String, add role-clarifying words to the name.

// GOOD — role is clear despite weak types
func addObserver(_ observer: NSObject, forKeyPath path: String)

// BAD — what does "string" mean here?
func add(_ object: NSObject, for string: String)

For extended naming examples and patterns, see references/naming-and-clarity.md.

Fluent Usage and Protocols

Call sites read as grammatical English. Prefer names that form grammatical phrases at the point of use.

// GOOD — reads fluently
x.insert(y, at: z)          // "x, insert y at z"
x.subviews.remove(at: i)    // "x's subviews, remove at i"
x.makeIterator()             // "x, make iterator"

// BAD — ungrammatical
x.insert(y, position: z)
x.subviews.remove(i)

Initializer first argument. The first argument to an initializer should not form a phrase continuing the type name.

// GOOD
let foreground = Color(red: 32, green: 64, blue: 128)

// BAD — "Color with red" reads awkwardly
let foreground = Color(havingRGBValuesRed: 32, green: 64, blue: 128)

Protocol naming conventions:

Protocol describesNaming patternExamples
What something isNounCollection, IteratorProtocol
A capability-able, -ible, or -ing suffixEquatable, Hashable, Sendable

General Conventions

Casing. Types and protocols use UpperCamelCase. Everything else uses lowerCamelCase. Acronyms that are commonly all-caps in American English appear uniformly upper- or lower-cased based on position.

var utf8Bytes: [UTF8.CodeUnit]
var isRepresentableAsASCII = true
var userSMTPServer: SMTPServer

Methods and properties over free functions. Prefer methods and properties. Use free functions only when:

  1. There is no obvious selfmin(x, y)
  2. The function is an unconstrained generic — print(value)
  3. The function syntax is established domain notation — sin(x)

Default arguments over method families. Prefer a single method with default parameters over a family of methods that differ only in which parameters they accept. Place defaulted parameters at the end. Parameters with default values should always have argument labels — defaulted parameters are usually omitted at call sites, so their labels must be clear when they do appear.

// GOOD — labeled with defaults
func decode(_ data: Data, encoding: String.Encoding = .utf8) -> String?

// BAD — method family
func decode(_ data: Data) -> String?
func decode(_ data: Data, encoding: String.Encoding) -> String?

Overload safety. Methods may share a base name when they operate in different type domains or when their meaning is clear from context. Avoid return-type-only overloads that cause ambiguity at the call site.

For casing edge cases, overload patterns, and tuple/closure naming, see references/conventions-and-special-rules.md.

Common Mistakes

  1. Omitting needed argument labels. Using remove(position) instead of remove(at: position) when the role of the argument is ambiguous without the label.
  2. Using -ed when -ing is correct. Applying stripped() when the past participle is ungrammatical — use stripping() instead. Test: does "a [verb]-ed [noun]" read naturally?
  3. Using verb names for side-effect-free operations. Naming a nonmutating method sort() that returns a new collection — use sorted() to signal no mutation.
  4. Naming by type instead of role. Using string instead of greeting, or array instead of elements, when the role would be more informative.
  5. Missing documentation comments. Leaving public declarations undocumented, or writing summaries that describe the implementation rather than the purpose.
  6. Not documenting non-O(1) computed properties. Exposing a linear-time computed property without a Complexity: note, causing callers to assume O(1) and use it in loops.
  7. Applying form- prefix to verb-based operations. Writing formSort() instead of just sort() — the form prefix is only for noun-based operations (formUnion).
  8. Factory methods without make- prefix. Naming factory methods as createIterator() or buildBuffer() instead of makeIterator() and makeBuffer().
  9. Repeating type information in names. Writing removeElement(cancelButton) or stringValue: String when the type is already evident from context.
  10. Return-type-only overloads. Defining overloads that differ only in return type, creating ambiguity when the compiler cannot infer the expected type.
  11. Unlabeled tuple members and closure parameters. Exposing tuples or closures in public API without naming their components, forcing callers to use positional access.

Review Checklist

Argument Labels

  • First argument follows the correct label rule (grammatical phrase, prepositional, conversion, or labeled)
  • Prepositional labels do not incorrectly group independent arguments
  • Value-preserving conversion initializers omit the first label
  • All non-special-case arguments have labels

Naming Semantics

  • Mutating methods use imperative verb form
  • Nonmutating methods use -ed/-ing or noun form
  • Mutating/nonmutating pairs follow the correct pattern (verb pair or noun/form-noun pair)
  • Boolean properties read as assertions (isEmpty, isValid, contains)
  • Variables and parameters are named by role, not type

Documentation

  • Every public declaration has a doc comment
  • Summaries are single sentence fragments ending in a period
  • Summaries describe the correct thing per declaration kind (action, access, creation, entity)
  • Non-O(1) computed properties document their complexity
  • Parameters, return values, and thrown errors are documented with symbol markup

Conventions

  • Types and protocols use UpperCamelCase; everything else uses lowerCamelCase
  • Acronyms are uniformly cased based on position
  • Default arguments are preferred over method families
  • Overloads do not differ only in return type
  • Protocol names follow the noun (is-a) or suffix (capability) convention

References

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

35.14%
按下载量换算410

Claude

30.04%
按下载量换算351

Cursor

20.16%
按下载量换算235

Gemini CLI

9.88%
按下载量换算115

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills