Swift idioms — optionals, value types, actors, async/await, protocols, and Result builders. Auto-load when working with .swift files, Package.swift, or when the user mentions Swift, SwiftUI, actors, async/await, Sendable, Result builders, or Swift Package Manager.
التثبيت
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
Swift idioms — optionals, value types, actors, async/await, protocols, and Result builders. Auto-load when working with .swift files, Package.swift, or when the user mentions Swift, SwiftUI, actors, async/await, Sendable, Result builders, or Swift Package Manager.
Swift
Optionals
? makes absence explicit in the type — String? vs String.
if let / guard let unwrap safely. guard exits scope immediately — prefer it for preconditions.
?? provides a default for nil. Never force-unwrap (!) in production unless the nil case is a programmer error that should crash loudly.
Swift markup — /// doc comment: a single-sentence summary; add - Parameters:/- Returns: only for a non-obvious contract (units, side effects, thrown-error meaning).
/// Returns the cached price, refreshing it if older than `maxAge`.funcprice(forsymbol: String, maxAge: TimeInterval) asyncthrows -> Decimal
Packaging — Swift Package Manager
Package.swift is the modern standard. Avoid CocoaPods / Carthage in new projects.
One target per logical module. Keep Sources/ layout mirroring the module name.
Pin dependencies via Package.resolved in version control for reproducible builds.
Tooling
Format:swiftformat . (nicklockwood/SwiftFormat) orswift-format format -i -r . (Apple — incompatible config; pick one per project)
Lint:swiftlint lint
Test:swift test (see Testing below)
Testing
XCTest: XCTAssertEqual, XCTUnwrap (throws if nil, cleaner than force-unwrap in tests).
Swift Testing (@Test, #expect) for new projects on Swift 6.0+ (Xcode 16+).