name: swift-language description: Use when writing or reviewing Swift language features, ownership, noncopyable types, InlineArray, Span, typed throws, or C bounds safety.
Swift Language
Review and write code using modern Swift language features and standard library types for correctness and performance.
Responsibility
Owns: Ownership modifiers (borrowing, consuming, inout, consume operator), noncopyable types (~Copyable), InlineArray, Span family (Span, MutableSpan, RawSpan, MutableRawSpan, OutputSpan, UTF8Span), value generics, typed throws, Result builders, property wrappers, macros, Codable protocol patterns (synthesis, CodingKeys, manual implementation, date strategies, error handling), Swift standard library evolution, and C -fbounds-safety adoption guidance.
Does NOT own: Swift concurrency (swift-concurrency skill), Synchronization framework — Mutex/Atomic (swift-concurrency skill), SwiftUI, persistence, networking, Apple framework-specific APIs.
Core Principles
- Apple bounds-safety guidance wins. If C code uses or is adopting
-fbounds-safety,ptrcheck.h,__counted_by,__sized_by,__ended_by,__single,__indexable,__bidi_indexable,__unsafe_indexable,__null_terminated, or related helpers/macros, readreferences/apple-c-bounds-safety/before changing code. - Let the compiler choose ownership by default. Only add
borrowing,consuming, orinoutwhen profiling shows a benefit or when working with~Copyabletypes (where it's required). Note:MutexandAtomicfrom the Synchronization framework rely on these ownership mechanics internally; use theswift-concurrencyskill for usage guidance. - InlineArray for fixed-size, heap-free collections. Only when the size is known at compile time and the collection is never resized. For everything else, use Array.
- Span for safe contiguous memory access. Replace UnsafeBufferPointer with Span when possible. Let the compiler enforce lifetime safety.
- Respect non-escapability. Spans cannot escape their scope, be captured in closures, or outlive their source. This is a feature, not a limitation.
- Value generics enable type-level constants.
InlineArray<let count: Int, Element>makes size part of the type — mismatched sizes are compile errors. - Prefer Array unless profiling proves otherwise. InlineArray, Span, and ownership modifiers are optimisation tools. Don't reach for them prematurely.
- Reference-first for Swift 6.2 types. These features may post-date training data. Always consult reference docs before writing or reviewing code — never rely on model knowledge alone.
Decision Tree
Which Swift language feature?
├─ C code using or adopting -fbounds-safety / ptrcheck annotations?
│ └─ → references/apple-c-bounds-safety/
├─ Codable conformance, JSON encoding/decoding, CodingKeys?
│ └─ → references/codable-patterns.md
├─ Working with ~Copyable type?
│ └─ Required: borrowing/consuming on all methods → references/ownership-modifiers.md
├─ Fixed-size collection, no heap allocation?
│ └─ InlineArray<let count, Element> → references/inline-array-and-span.md
├─ Safe pointer-like access to contiguous memory?
│ ├─ Read-only elements → Span<Element>
│ ├─ Mutable elements → MutableSpan<Element>
│ └─ Raw bytes → RawSpan / MutableRawSpan
│ └─ → references/inline-array-and-span.md
├─ Large value type passed frequently + visible in profiler?
│ ├─ Read-only → borrowing
│ └─ Final use → consuming
│ └─ → references/ownership-modifiers.md
├─ ARC traffic visible in profiler?
│ └─ borrowing for read-only ref types → references/ownership-modifiers.md
└─ Otherwise → Let compiler choose (no annotation needed)
Review Process
- Check Codable conformance patterns →
references/codable-patterns.md - Check ownership modifier usage →
references/ownership-modifiers.md - Check InlineArray and Span usage →
references/inline-array-and-span.md - Verify Span lifetime safety (no escaping, no post-mutation access)
- Verify InlineArray is appropriate (truly fixed-size, not frequently copied)
- Verify ownership modifiers aren't applied to small/trivial types
References
references/apple-c-bounds-safety/— Apple-authoritative C-fbounds-safetylanguage model, adoption strategies, build settings, runtime debugging, and common patterns/pitfalls.references/codable-patterns.md— Codable synthesis, CodingKeys, date strategies, error handling, anti-patternsreferences/ownership-modifiers.md— borrowing, consuming, inout, ~Copyable types, limitationsreferences/inline-array-and-span.md— InlineArray, Span family, memory layout, safety constraints