Swift guide: code style, API design, concurrency, Swift 6.x. TRIGGER when: discussing, planning, or developing with Swift OR editing .swift files OR Package.swift present.
Guidance for Swift development grounded in the Swift API Design Guidelines and updated for Swift 6.3.
var greeting: String — not var string: Stringx.insert(y, at: z) — not x.insert(y, position: z)x.distance(to: y) / Side-effects → imperative verb: x.sort()sort() / sorted(), formUnion() / union()isEmpty, isDisjoint(with:), canBecomeFirstResponderUpperCamelCase / Everything else → lowerCamelCaseutf8Bytes, HTTPSConnection{ on same line, } else { togetherif condition {!) and force cast (as!) are strongly discouraged. If used, a comment explaining why it is safe is required.try! is generally forbidden. Exception: tests, or compile-time-provable safety (e.g., regex from literal).Optional or non-optional.weak over unowned to prevent crashes from deallocated objects.These are the most impactful modern Swift patterns. Read the version-specific reference files for details.
Concurrency (biggest area of change):
defaultIsolation (6.2+) instead of annotating every type with @MainActornonisolated async functions now stay on the caller's executor (6.2+) — use @concurrent when you actually need parallel executionnonisolated on types/extensions (6.1+) to opt out of inherited actor isolation cleanlyasync defer (6.3+) — defer blocks can now awaitType System:
throws(MyError) (6.0+) for precise error contractsInlineArray / [N of Element] (6.2+) for fixed-size stack-allocated buffers@nonexhaustive enum (6.3+) for library enums that may grow casesInterop & Modules:
@c (6.3+) replaces @_cdecl for C interop — use the official attributeModuleA::symbol (6.3+) resolve name conflicts without renaming importspublic import / internal import (6.0+) to control dependency exposurePerformance:
@inline(always) (6.3+) now guarantees inlining (was hint-only before)@export(implementation) (6.3+) replaces @_alwaysEmitIntoClientRead the relevant reference file when you need rules beyond this quick reference.
references/style-guide.md — Full Style GuideWhen to read: detailed formatting and line-wrapping rules, naming conventions with examples, documentation comment standards, file organization patterns, access control guidelines, pattern matching rules, trailing closure conventions, delegate naming, self usage, optional handling, attribute ordering, and performance coding practices.
Read the file matching the target Swift version. Each file instructs to also read lower-version files.
references/swift-6_0.md — Data race safety, typed throws, noncopyable types, import access controlreferences/swift-6_1.md — nonisolated on types, TaskGroup inference, trailing comma expansionreferences/swift-6_2.md — Default MainActor, @concurrent, InlineArray, Span, strict memory safetyreferences/swift-6_3.md — @c interop, module selectors ::, @nonexhaustive enum, async deferreferences/swift-migration.md — Migration & Best PracticesWhen to read: migrating to Swift 6 language mode, deciding which modern patterns to adopt/avoid, understanding breaking changes across versions.
references/official-packages.md — Official Swift PackagesWhen to read: choosing the right data structure (Collections), applying sequence/collection algorithms (Algorithms), working with async streams (Async Algorithms), or doing numerical computing (Numerics). These are official Apple-maintained packages that may eventually graduate to the standard library.
references/spm.md — Swift Package ManagerWhen to read: writing Package.swift, managing dependencies (version requirements, local/binary targets, traits), resource bundling, build settings (swiftSettings/cSettings), mixed C/ObjC targets, plugins, module aliasing, package security (signing/TOFU), version-specific packaging.
The reference files in this skill are derived from the sources below. Consult them when information is insufficient or freshness is uncertain. Also use these sources when updating reference files.