npx skills add ...
npx skills add dpearson2699/swift-ios-skills --skill swift-language
Apply modern Swift language patterns and idioms for non-concurrency, non-SwiftUI code. Covers if/switch expressions (Swift 5.9+), typed throws (Swift 6+), result builders, property wrappers, opaque and existential types (some vs any), guard patterns, Never type, Regex builders (Swift 5.7+), basic Codable shaping (CodingKeys, custom decoding, nested containers), modern collection APIs (count(where:), contains(where:), replacing()), basic FormatStyle usage, and string interpolation patterns. Use when writing core Swift code involving generics, protocols, enums, closures, or modern language features; route deep Codable to swift-codable, detailed formatting/localization to swift-formatstyle, and API naming to swift-api-design-guidelines.
npx skills add dpearson2699/swift-ios-skills --skill swift-language
Apply current Swift language syntax without changing behavior or evaluation order.
Route deep decoding to swift-codable, formatting to swift-formatstyle, naming
to swift-api-design-guidelines, concurrency to swift-concurrency, and SwiftUI
state/view work to swiftui-patterns.
For modernization, pin current behavior and evaluation order, make one semantic rewrite, compile the affected module, and run focused fixtures/tests. Fix any change before continuing; repeat until behavior is preserved.
Swift 5.9+ allows if and switch as expressions that return values. Use them
to assign, return, or initialize directly.
Rules:
Swift 6+ allows specifying the error type a function throws.
Rules:
throws(SomeError) only when callers benefit from exhaustive error
handling. For mixed error sources, use untyped throws.throws(ErrorEnum) and note Swift 6+.throws(Never) marks a function that syntactically throws but never actually
does -- useful in generic contexts.throws(A) and throws(B) must
itself throw a type that covers both (or use untyped throws).@resultBuilder enables DSL-style syntax. SwiftUI's @ViewBuilder is the most
common example, but you can create custom builders for any domain.
Builder methods: buildBlock (combine statements), buildExpression (single value), buildOptional (if without else), buildEither (if/else), buildArray (for..in), buildFinalResult (optional post-processing).
Custom @propertyWrapper types encapsulate storage and access patterns.
Design rules:
wrappedValue is the primary getter/setter.projectedValue (accessed via $property) provides metadata or bindings.@A @B var x applies outer wrapper first.some Protocol (Opaque Type)The caller does not know the concrete type, but the compiler does. A -> some P
return has one fixed underlying concrete type across all return branches.
Use some for:
some P is shorthand for an unnamed generic
parameter such as <T: P>.any Protocol (Existential Type)An existential box that can hold any conforming type at runtime. It uses dynamic dispatch and may allocate when the value does not fit in the inline buffer.
Use some | Use any |
|---|---|
| Return type hiding concrete type | Heterogeneous collections |
| Function parameters (replaces simple generics) | Dynamic type erasure needed |
| Better performance (static dispatch) | Protocol has Self or associated type requirements you need to erase |
Rule of thumb: Default to some. Use any only when you need a
heterogeneous collection or runtime type flexibility.
guard enforces preconditions and enables early exit. It keeps the happy path
left-aligned and reduces nesting.
Best practices:
guard for preconditions, if for branching logic.guard let a, let b else { return }.else block must exit scope: return, throw, continue, break, or
fatalError().guard let value else { ... } (Swift 5.7+).Never is an uninhabited type for code paths that never produce a value. It
behaves like Swift's bottom type only where a value expression can be used or
inferred; it is not a universal type witness, does not implicitly conform to
arbitrary protocols, and cannot satisfy generic constraints such as T: P
unless the constraint is otherwise valid for Never.
Swift 5.7+ Regex builder DSL provides compile-time checked, readable patterns.
When to use builder vs. literal:
/pattern/): simple patterns, familiarity with regex syntax./.../ literals inside builder blocks.Use CodingKeys for simple renames and custom decoding only for real payload
shape or transformation mismatches. Load
extended Swift patterns for a compact
language example; use swift-codable for implementation and verification.
Prefer these modern APIs over manual loops:
Use .formatted() and Text(_:format:) for basic display. Route style
selection, parsing, localization testing, and reusable formatter design to
swift-formatstyle.
Extend DefaultStringInterpolation for domain-specific formatting. Use """ for multi-line strings (indentation is relative to the closing """). See references/swift-patterns-extended.md for custom interpolation examples.
any when some works. Default to some for return types and
parameters, but every -> some P branch must return the same concrete type..filter { }.count instead of collection APIs. Use
count(where:) for conditional counts, plus contains(where:),
compactMap, and flatMap instead of extra iteration or arrays.DateFormatter instead of FormatStyle. .formatted() is simpler,
type-safe, and handles localization automatically.decodeIfPresent with defaults
for optional or missing keys.guard without moving
normalization or transformations before validation.@c signatures. Say UnsafeBufferPointer is a Swift struct/value
wrapper, then reject String, Array, closures, and generic placeholders.Never. For Result<T, Never> or throws(Never), write the caveat explicitly: Never does not implicitly conform to arbitrary protocols, cannot satisfy arbitrary T: P constraints, and is bottom-like only in valid expression/inference contexts.CodingKeys, decoders, formatters, SwiftUI, or concurrency.some used only when every opaque-return branch has one concrete typeguard for preconditions; count(where:) instead of manual counting or .filter { }.count.formatted() used instead of DateFormatter/NumberFormatterCodingKeys for API mapping; decodeIfPresent with defaults for optional fields@c corrections call UnsafeBufferPointer a Swift struct/value wrapper and enumerate rejected Swift-only types by nameNever guidance uses uninhabited and bottom-like, and says no implicit arbitrary protocol/generic conformanceswift-codable; FormatStyle APIs to swift-formatstyle; market/localized-display QA to ios-localization; naming/concurrency/SwiftUI routed to sibling skills