### Install Swift API Design Guidelines Skill via skills.sh Source: https://context7.com/erikote04/swift-api-design-guidelines-agent-skill/llms.txt Use this command to install the skill into compatible AI coding tools. After installation, prompt your agent to use the skill for code review. ```bash npx skills add https://github.com/Erikote04/Swift-API-Design-Guidelines-Agent-Skill \ --skill swift-api-design-guidelines-skill # Then prompt your agent: # "Use the swift-api-design-guidelines skill and review this code for naming, # argument labels, and API clarity." ``` -------------------------------- ### Manual Installation of Swift API Design Guidelines Skill Source: https://context7.com/erikote04/swift-api-design-guidelines-agent-skill/llms.txt Instructions for manual installation by cloning the repository and then linking or copying the skill into the AI tool's designated skills directory. ```bash git clone https://github.com/Erikote04/Swift-API-Design-Guidelines-Agent-Skill.git # Symlink or copy swift-api-design-guidelines-skill/ into your tool's skills directory # per its official documentation. ``` -------------------------------- ### Install Swift API Design Guidelines Skill as a Claude Code Plugin (personal) Source: https://context7.com/erikote04/swift-api-design-guidelines-agent-skill/llms.txt Steps to install the skill as a personal plugin within Claude Code. This involves registering the marketplace source and then installing the skill. ```bash # 1. Register the marketplace source /plugin marketplace add Erikote04/Swift-API-Design-Guidelines-Agent-Skill # 2. Install the skill /plugin install swift-api-design-guidelines@swift-api-design-guidelines-skill ``` -------------------------------- ### Documenting an Initializer in Swift Source: https://github.com/erikote04/swift-api-design-guidelines-agent-skill/blob/main/swift-api-design-guidelines-skill/references/fundamentals.md Document initializers by explaining what they create. This example demonstrates documenting an initializer that creates an instance with repeated elements. ```swift /// Creates an instance containing `n` repetitions of `x`. init(count n: Int, repeatedElement x: Element) ``` -------------------------------- ### Swift: Factory and Initializer Naming Source: https://github.com/erikote04/swift-api-design-guidelines-agent-skill/blob/main/swift-api-design-guidelines-skill/references/strive-for-fluent-usage.md Start factory methods with `make`. Avoid forcing the first argument into a phrase with the base name. ```swift factory.makeWidget(gears: 42, spindles: 14) let link = Link(to: destination) ``` -------------------------------- ### Documenting a Function in Swift Source: https://github.com/erikote04/swift-api-design-guidelines-agent-skill/blob/main/swift-api-design-guidelines-skill/references/fundamentals.md Use documentation comments to explain what a function does and what it returns. This example shows how to document a `reversed()` function. ```swift /// Returns a "view" of `self` containing the same elements in /// reverse order. func reversed() -> ReverseCollection ``` -------------------------------- ### Install Swift API Design Guidelines Skill for Claude Code Source: https://github.com/erikote04/swift-api-design-guidelines-agent-skill/blob/main/README.md Install the Swift API Design Guidelines skill for personal use within Claude Code after adding the marketplace. This makes the skill available for your projects. ```bash /plugin install swift-api-design-guidelines@swift-api-design-guidelines-skill ``` -------------------------------- ### Add Swift API Design Guidelines Skill using skills.sh Source: https://github.com/erikote04/swift-api-design-guidelines-agent-skill/blob/main/README.md Install the Swift API Design Guidelines skill using the skills.sh command-line tool. This is the recommended method for integrating the skill. ```bash npx skills add https://github.com/Erikote04/Swift-API-Design-Guidelines-Agent-Skill --skill swift-api-design-guidelines-skill ``` -------------------------------- ### Documenting a Subscript in Swift Source: https://github.com/erikote04/swift-api-design-guidelines-agent-skill/blob/main/swift-api-design-guidelines-skill/references/fundamentals.md Document subscripts by explaining what they access. This example shows the documentation for a subscript that accesses an element by its index. ```swift /// Accesses the `index`th element. subscript(index: Int) -> Element { get set } ``` -------------------------------- ### Swift API Design: Documentation Comment Examples Source: https://context7.com/erikote04/swift-api-design-guidelines-agent-skill/llms.txt Illustrates the correct usage of documentation comments for Swift functions, subscripts, and initializers, emphasizing clarity and descriptive summaries. ```swift // ✅ Function: describe what it does and what it returns /// Returns a "view" of `self` containing the same elements in reverse order. func reversed() -> ReverseCollection ``` ```swift // ✅ Subscript: describe what it accesses /// Accesses the `index`th element. subscript(index: Int) -> Element { get set } ``` ```swift // ✅ Initializer: describe what it creates /// Creates an instance containing `n` repetitions of `x`. init(count n: Int, repeatedElement x: Element) ``` ```swift // ✅ Use recognized symbol markup for parameters, returns, and errors /// Inserts `newElement` into the collection at `position`. /// /// - Parameters: /// - newElement: The element to insert. /// - position: The index at which to insert the element. /// - Returns: The index of the inserted element. /// - Throws: `CollectionError.outOfBounds` if `position` exceeds `endIndex`. /// - Note: Invalidates all existing indices after `position`. @discardableResult mutating func insert(_ newElement: Element, at position: Index) throws -> Index ``` -------------------------------- ### Prepositional Phrase Argument Labels Source: https://github.com/erikote04/swift-api-design-guidelines-agent-skill/blob/main/swift-api-design-guidelines-skill/references/argument-labels.md Include argument labels that start with a preposition when the first argument is part of a prepositional phrase. This clarifies the relationship between the argument and the method. ```swift x.removeBoxes(havingLength: 12) ``` -------------------------------- ### Filter Function Signature Source: https://github.com/erikote04/swift-api-design-guidelines-agent-skill/blob/main/swift-api-design-guidelines-skill/references/parameters.md Use descriptive parameter names that improve documentation clarity. This example shows a filter function where the predicate parameter name is crucial for understanding its purpose in documentation. ```swift /// Returns the elements of `self` that satisfy `predicate`. func filter(_ predicate: (Element) -> Bool) -> [Element] ``` -------------------------------- ### Swift Casing Conventions for Declarations Source: https://github.com/erikote04/swift-api-design-guidelines-agent-skill/blob/main/swift-api-design-guidelines-skill/references/general-conventions.md Illustrates Swift's casing conventions for types, protocols, and other declarations. Ensure acronyms and initialisms are cased consistently. ```swift var utf8Bytes: [UTF8.CodeUnit] var isRepresentableAsASCII = true var radarDetector: RadarScanner ``` -------------------------------- ### Strive for Fluent Usage: Method Naming and Style Source: https://context7.com/erikote04/swift-api-design-guidelines-agent-skill/llms.txt Design method names to form grammatical English phrases. Use 'make' for factory methods, noun/query style for non-mutating operations, and imperative verb style for operations with side effects. Ensure mutating/nonmutating pairs follow consistent suffixing rules. ```swift // ✅ Grammatical call sites x.insert(y, at: z) x.subviews(havingColor: color) ``` ```swift // ✅ Factory methods start with "make" factory.makeWidget(gears: 42, spindles: 14) // ❌ Ambiguous factory naming factory.createWidget(gears: 42, spindles: 14) ``` ```swift // ✅ No side effects → noun/query style let d = origin.distance(to: target) guard cache.isEmpty else { ... } ``` ```swift // ✅ Side effects → imperative verb style list.sort() buffer.append(element) ``` ```swift // ✅ Mutating/nonmutating pairs — verb-based array.sort() // mutating: imperative let sorted = array.sorted() // nonmutating: participle ``` ```swift // ✅ Mutating/nonmutating pairs — noun-based let result = setA.union(setB) // nonmutating: noun setA.formUnion(setB) // mutating: "form" prefix ``` ```swift // ✅ Protocol naming protocol Collection { ... } // describes what it IS → noun protocol Equatable { ... } // capability → "-able" protocol ProgressReporting { ... } // capability → "-ing" ``` -------------------------------- ### Use Standard Mathematical Functions Source: https://github.com/erikote04/swift-api-design-guidelines-agent-skill/blob/main/swift-api-design-guidelines-skill/references/use-terminology-well.md In domains like mathematics, use standard function names like `sin(x)` for conciseness and recognition by experts. ```swift let sineValue = sin(x) ``` -------------------------------- ### Add Swift API Design Guidelines Skill for Claude Code (Marketplace) Source: https://github.com/erikote04/swift-api-design-guidelines-agent-skill/blob/main/README.md Add the Swift API Design Guidelines skill to your personal Claude Code environment by first adding the marketplace. This allows for personal usage. ```bash /plugin marketplace add Erikote04/Swift-API-Design-Guidelines-Agent-Skill ``` -------------------------------- ### Swift API Design Guidelines Skill Structure Source: https://github.com/erikote04/swift-api-design-guidelines-agent-skill/blob/main/README.md This text block outlines the directory structure and key reference files within the Swift API Design Guidelines Skill. It helps understand where specific guidance is located. ```text swift-api-design-guidelines-skill/ SKILL.md references/ argument-labels.md - Rules for first-argument labels, grammar, and conversion cases fundamentals.md - Core priorities and documentation-comment principles general-conventions.md - Complexity docs, casing, free-function exceptions, overload conventions parameters.md - Parameter naming, defaults, ordering, and file literal guidance promote-clear-usage.md - Naming clarity, omitted words, and role-based identifiers special-instructions.md - Tuple/closure naming and weak-type overload disambiguation strive-for-fluent-usage.md - Fluent call-site phrasing and mutating/nonmutating naming pairs use-terminology-well.md - Terms of art, abbreviations, and precedent ``` -------------------------------- ### Parameter Naming and Default Values in Swift Source: https://context7.com/erikote04/swift-api-design-guidelines-agent-skill/llms.txt Use natural-sounding parameter names for documentation and default values to simplify common use cases. Place defaulted parameters at the end of the parameter list. ```swift // ✅ Parameter names that read naturally in documentation /// Returns the elements of `self` that satisfy `predicate`. func filter(_ predicate: (Element) -> Bool) -> [Element] // ❌ "includeElement" is less natural in documentation prose func filter(_ includeElement: (Element) -> Bool) -> [Element] ``` ```swift // ✅ Default values for commonly-used arguments reduce call-site noise extension String { /// Compares this string to `other` using the given options. func compare( _ other: String, options: CompareOptions = [], locale: Locale? = .current ) -> ComparisonResult } ``` ```swift // Common usage — defaults eliminate noise lastName.compare(royalFamilyName) // Full control still available lastName.compare(royalFamilyName, options: .caseInsensitive, locale: .init(identifier: "en")) ``` ```swift // ✅ Single API with defaults preferred over method families // ❌ Avoid this — three separate methods, same semantics func compare(_ other: String) -> ComparisonResult func compare(_ other: String, options: CompareOptions) -> ComparisonResult func compare(_ other: String, options: CompareOptions, locale: Locale?) -> ComparisonResult ``` ```swift // ✅ File literal guidance for production vs tooling APIs func log( _ message: String, file: String = #fileID, // production: compact, no full paths exposed line: Int = #line ) { ... } func assert( _ condition: Bool, file: StaticString = #filePath, // test/tool context: full path useful line: UInt = #line ) { ... } ``` -------------------------------- ### Promote Clear Usage: Parameter Names and Labels Source: https://context7.com/erikote04/swift-api-design-guidelines-agent-skill/llms.txt Use descriptive parameter names and labels to avoid ambiguity, especially with weakly typed values. Omit labels only when they are redundant or when the parameter is clearly identified by its position. ```swift // ✅ Include words needed to avoid ambiguity employees.remove(at: index) // clearly position-based // ❌ Ambiguous without the label employees.remove(index) ``` ```swift // ✅ Omit needless type-repetition words allViews.remove(cancelButton) // ❌ "Element" adds no meaning beyond the type allViews.removeElement(cancelButton) ``` ```swift // ✅ Name by role, not type var greeting = "Hello" func restock(from supplier: WidgetFactory) associatedtype ContentView: View // ❌ Type name reused as identifier var string = "Hello" func restock(from widgetFactory: WidgetFactory) ``` ```swift // ✅ Compensate for weak type information with role nouns func addObserver(_ observer: NSObject, forKeyPath path: String) // ❌ "path: String" alone is ambiguous; "forKeyPath" clarifies role func addObserver(_ observer: NSObject, path: String) ``` -------------------------------- ### Swift General Conventions: Properties, Functions, and Overloads Source: https://context7.com/erikote04/swift-api-design-guidelines-agent-skill/llms.txt Document non-O(1) computed property complexity and prefer methods/properties over free functions when a natural 'self' exists. Adhere to Swift casing and design semantically coherent overloads. ```swift // ✅ Document non-O(1) computed property complexity extension Graph { /// The number of edges in the graph. /// /// - Complexity: O(V) where V is the number of vertices. var edgeCount: Int { vertices.reduce(0) { $0 + $1.edges.count } } } ``` ```swift // ✅ Free functions only when there is no natural "self" min(x, y) // no obvious self zip(seq1, seq2) // no obvious self ``` ```swift // ✅ Swift casing conventions struct HTTPSConnection { ... } // type: UpperCamelCase; acronym kept var utf8Bytes: [UTF8.CodeUnit] // property: lowerCamelCase var isRepresentableAsASCII = true // acronym at end: all caps var radarDetector: RadarScanner // acronym mid-word: UpperCamelCase ``` ```swift // ✅ Overloads: same base name only when semantics match or domains differ extension Shape { func contains(_ point: Point) -> Bool { ... } func contains(_ region: Region) -> Bool { ... } } // ❌ Do not overload on return type alone — type inference causes ambiguity extension Collection { func element() -> Int { ... } func element() -> String { ... } // which gets called? depends on context } ``` -------------------------------- ### Swift: Grammatical Call Sites Source: https://github.com/erikote04/swift-api-design-guidelines-agent-skill/blob/main/swift-api-design-guidelines-skill/references/strive-for-fluent-usage.md Use names that form readable phrases at use sites. Fluency matters most for the base name and first arguments. ```swift x.insert(y, at: z) x.subviews(havingColor: color) ``` -------------------------------- ### Using Terminology and Abbreviations in Swift Source: https://context7.com/erikote04/swift-api-design-guidelines-agent-skill/llms.txt Employ common words for clarity unless a specific term of art is necessary. Preserve the exact meaning of established terms and use widely recognized abbreviations. ```swift // ✅ Use common words unless precision requires a term of art func concatenate(_ other: Self) -> Self // clear to all readers // ❌ Over-specialized without added precision func catenate(_ other: Self) -> Self ``` ```swift // ✅ Preserve the established meaning of terms of art // "Predecessor" in a tree context has an exact meaning — keep it var predecessor: Node? ``` ```swift // ✅ Embrace established domain precedent — don't reinvent standard names struct Array { ... } // not "List" or "Sequence" func sin(_ x: Double) -> Double // mathematical precedent; no need to rename ``` ```swift // ✅ Abbreviations: only when widely established let urlSession = URLSession.shared // "URL" is universally known let jsonData = try encoder.encode(value) // "JSON" is standard // ❌ Non-standard abbreviations become hidden terms of art let svc = NetworkService() // "svc" is non-standard; use "service" let mgr = FileManager.default // "mgr" is non-standard; use "manager" ``` -------------------------------- ### Configure Claude Code for Swift API Design Guidelines Skill Source: https://github.com/erikote04/swift-api-design-guidelines-agent-skill/blob/main/README.md Automatically provide the Swift API Design Guidelines skill to all team members by configuring the .claude/settings.json file. This ensures consistent API review practices within a project. ```json { "enabledPlugins": { "swift-api-design-guidelines@swift-api-design-guidelines-skill": true }, "extraKnownMarketplaces": { "swift-api-design-guidelines-skill": { "source": { "source": "github", "repo": "Erikote04/Swift-API-Design-Guidelines-Agent-Skill" } } } } ``` -------------------------------- ### Defaulted Parameter Usage Source: https://github.com/erikote04/swift-api-design-guidelines-agent-skill/blob/main/swift-api-design-guidelines-skill/references/parameters.md Demonstrates calling a function with a defaulted parameter. Defaults reduce noise in common call sites and improve readability by omitting commonly used values. ```swift lastName.compare(royalFamilyName) ``` -------------------------------- ### Prefer Standard Types Source: https://github.com/erikote04/swift-api-design-guidelines-agent-skill/blob/main/swift-api-design-guidelines-skill/references/use-terminology-well.md Use established types like `Array` instead of creating custom synonyms to ensure clarity and interoperability. ```swift let list = Array() ``` -------------------------------- ### Include Words for Clarity in Swift Source: https://github.com/erikote04/swift-api-design-guidelines-agent-skill/blob/main/swift-api-design-guidelines-skill/references/promote-clear-usage.md Keep all words required to avoid ambiguity at the call site. Do not remove words that carry semantic distinction. ```swift employees.remove(at: index) // clear position-based removal ``` ```swift employees.remove(index) // ambiguous ``` -------------------------------- ### Prepositional Phrase Exception Source: https://github.com/erikote04/swift-api-design-guidelines-agent-skill/blob/main/swift-api-design-guidelines-skill/references/argument-labels.md When the first arguments are part of a single abstraction, move the label boundary after the preposition. This groups related parameters under a common prepositional phrase. ```swift a.moveTo(x: b, y: c) ``` ```swift a.fadeFrom(red: b, green: c, blue: d) ``` -------------------------------- ### Naming Tuple Members and Closure Parameters in Swift Source: https://github.com/erikote04/swift-api-design-guidelines-agent-skill/blob/main/swift-api-design-guidelines-skill/references/special-instructions.md Label tuple members in API signatures and name closure parameters where they appear in the API. These names improve call-site readability and documentation usefulness. ```swift mutating func ensureUniqueStorage( minimumCapacity requestedCapacity: Int, allocate: (_ byteCount: Int) -> UnsafePointer ) -> (reallocated: Bool, capacityChanged: Bool) ``` -------------------------------- ### Name By Role, Not Type in Swift Source: https://github.com/erikote04/swift-api-design-guidelines-agent-skill/blob/main/swift-api-design-guidelines-skill/references/promote-clear-usage.md Variables, parameters, and associated types should describe role. Avoid reusing type names as identifiers when a role name is better. ```swift var greeting = "Hello" ``` ```swift func restock(from supplier: WidgetFactory) ``` ```swift associatedtype ContentView: View ``` -------------------------------- ### Label All Other Arguments Source: https://github.com/erikote04/swift-api-design-guidelines-agent-skill/blob/main/swift-api-design-guidelines-skill/references/argument-labels.md Label the first argument if it's not part of a grammatical phrase, and label all subsequent arguments unless a specific rule allows omission. This ensures all parameters are explicitly named. ```swift view.dismiss(animated: false) ``` ```swift words.split(maxSplits: 12) ``` ```swift students.sorted(isOrderedBefore: Student.namePrecedes) ``` -------------------------------- ### Disambiguating Overloads in Swift Source: https://github.com/erikote04/swift-api-design-guidelines-agent-skill/blob/main/swift-api-design-guidelines-skill/references/special-instructions.md Preferred API naming to explicitly state the intent when dealing with potentially ambiguous overload situations, especially with weakly typed values. ```swift append(_ newElement: Element) append(contentsOf newElements: S) ``` -------------------------------- ### Argument Labels: Grammar and Precedence Source: https://context7.com/erikote04/swift-api-design-guidelines-agent-skill/llms.txt Omit argument labels when they preserve clarity, especially for positional arguments or value-preserving initializers. Use prepositional phrases for labels and fold leading words into the base name for grammatical phrases. ```swift // ✅ Omit all labels when arguments are indistinguishable by position min(x, y) zip(sequenceA, sequenceB) ``` ```swift // ✅ Value-preserving conversion initializers: omit first label let big = Int64(someUInt32) // source is the argument // ❌ Redundant "from:" label let big = Int64(from: someUInt32) ``` ```swift // ✅ First arg in prepositional phrase → label from the preposition x.removeBoxes(havingLength: 12) ``` ```swift // ✅ Exception: when two args form one abstraction, move boundary after preposition a.moveTo(x: b, y: c) a.fadeFrom(red: b, green: c, blue: d) ``` ```swift // ✅ First arg forms a grammatical phrase → omit label, fold into base name x.addSubview(y) // ❌ Redundant first label — "view" is already in the base name x.addSubview(view: y) ``` ```swift // ✅ First arg NOT part of any phrase → label it; label all remaining args view.dismiss(animated: false) words.split(maxSplits: 12) students.sorted(isOrderedBefore: Student.namePrecedes) ``` -------------------------------- ### Grammatical Phrase Argument Labels Source: https://github.com/erikote04/swift-api-design-guidelines-agent-skill/blob/main/swift-api-design-guidelines-skill/references/argument-labels.md Omit the label for the first argument and incorporate leading words into the base name if the argument forms part of a grammatical phrase. This creates a more natural language syntax. ```swift x.addSubview(y) ``` -------------------------------- ### Label Tuple Members and Name Closure Parameters in Swift Source: https://context7.com/erikote04/swift-api-design-guidelines-agent-skill/llms.txt Use readable member names for tuple members in return types and name closure parameters in public APIs for clarity. This prevents ambiguity, especially with unconstrained polymorphism. ```swift mutating func ensureUniqueStorage( minimumCapacity requestedCapacity: Int, allocate: (_ byteCount: Int) -> UnsafePointer ) -> (reallocated: Bool, capacityChanged: Bool) ``` ```swift let result = buffer.ensureUniqueStorage(minimumCapacity: 64, allocate: myAllocator) if result.reallocated { rebuildIndex() } if result.capacityChanged { notifyObservers() } ``` ```swift func animate( withDuration duration: TimeInterval, animations: (_ context: AnimationContext) -> Void, completion: (_ finished: Bool) -> Void ) { ... } ``` -------------------------------- ### Value-Preserving Conversion Initializers Source: https://github.com/erikote04/swift-api-design-guidelines-agent-skill/blob/main/swift-api-design-guidelines-skill/references/argument-labels.md Omit the first argument label for initializers that perform value-preserving conversions. The first argument should represent the source value being converted. ```swift let value = Int64(someUInt32) ``` -------------------------------- ### Disambiguate Overloads with Explicit Parameter Names in Swift Source: https://context7.com/erikote04/swift-api-design-guidelines-agent-skill/llms.txt Explicitly name parameters to disambiguate overloads, especially when weakly typed collections might collapse distinctions. Use `append(contentsOf:)` for sequences and `append(_:)` for single elements. ```swift // ❌ Ambiguous with weakly typed collections values.append([2, 3, 4]) // element append or sequence append? ``` ```swift extension Collection { mutating func append(_ newElement: Element) mutating func append(contentsOf newElements: S) where S.Element == Element } ``` ```swift values.append(contentsOf: [2, 3, 4]) // unambiguously a sequence append values.append(7) // unambiguously an element append ``` -------------------------------- ### Omit Needless Words in Swift Source: https://github.com/erikote04/swift-api-design-guidelines-agent-skill/blob/main/swift-api-design-guidelines-skill/references/promote-clear-usage.md Remove words that repeat type information and add no meaning. Prefer role-focused words over type-focused words. ```swift allViews.remove(cancelButton) // preferred ``` ```swift allViews.removeElement(cancelButton) // redundant ``` -------------------------------- ### Compensate for Weak Type Information in Swift Source: https://github.com/erikote04/swift-api-design-guidelines-agent-skill/blob/main/swift-api-design-guidelines-skill/references/promote-clear-usage.md Weakly typed values (`Any`, `NSObject`, primitives) often need extra role words. Add role nouns to disambiguate intent. ```swift func addObserver(_ observer: NSObject, forKeyPath path: String) ``` -------------------------------- ### Omit Labels for Unambiguous Arguments Source: https://github.com/erikote04/swift-api-design-guidelines-agent-skill/blob/main/swift-api-design-guidelines-skill/references/argument-labels.md Omit argument labels when the arguments are indistinguishable and their meaning is clear from context. This is often seen in mathematical or utility functions. ```swift min(x, y) ``` ```swift zip(a, b) ``` -------------------------------- ### Ambiguous Overload in Swift Source: https://github.com/erikote04/swift-api-design-guidelines-agent-skill/blob/main/swift-api-design-guidelines-skill/references/special-instructions.md This pattern can lead to ambiguity when appending to a collection, as it's unclear whether an element or a sequence is being appended. ```swift values.append([2, 3, 4]) // element append or sequence append? ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.