Swift language guardrails, patterns, and best practices for AI-assisted development.
Use when working with Swift files (.swift), Package.swift, or when the user mentions Swift.
Provides optionals handling, protocol-oriented patterns, concurrency with async/await,
and testing standards specific to this project's coding standards.
Installer avec Codex ou Claude Copiez ce prompt, collez-le dans Codex, Claude ou un autre assistant, puis laissez-le vérifier la page du skill et l'installer pour vous.
Une commande directe contourne le prompt de vérification. Examinez la source avant de l'exécuter.
Swift language guardrails, patterns, and best practices for AI-assisted development.
Use when working with Swift files (.swift), Package.swift, or when the user mentions Swift.
Provides optionals handling, protocol-oriented patterns, concurrency with async/await,
and testing standards specific to this project's coding standards.
protocolTimestamped {
var createdAt: Date { get }
var updatedAt: Date { get }
}
extensionTimestamped {
var isRecent: Bool { updatedAt.timeIntervalSinceNow >-86_400 }
}
// Protocol composition for flexible constraintsfuncfindRecent<T: Identifiable & Timestamped>(_items: [T]) -> [T] {
items.filter(\.isRecent)
}
funcfetchAllUsers(ids: [String]) asyncthrows -> [User] {
tryawait withThrowingTaskGroup(of: User.self) { group infor id in ids {
group.addTask { tryawaitself.fetchUser(id: id) }
}
var users: [User] = []
fortryawait user in group { users.append(user) }
return users
}
}
Sendable Conformance
// Value types: implicitly Sendable when all stored properties are SendablestructUserDTO: Sendable { let id: String; let name: String }
// Classes: must be final with immutable properties, or use @unchecked with a lockfinalclassAppConfig: Sendable { let apiBaseURL: URL; let maxRetries: Intinit(apiBaseURL: URL, maxRetries: Int=3) { self.apiBaseURL = apiBaseURL; self.maxRetries = maxRetries }
}
Property Wrappers
@propertyWrapperstructClamped<Value: Comparable> {
privatevar value: Valueprivatelet range: ClosedRange<Value>
var wrappedValue: Value {
get { value }
set { value =min(max(newValue, range.lowerBound), range.upperBound) }
}
init(wrappedValue: Value, _range: ClosedRange<Value>) {
self.range = range
self.value =min(max(wrappedValue, range.lowerBound), range.upperBound)
}
}
structAudioSettings {
@Clamped(0...100) var volume: Int=50@Clamped(0.5...2.0) var playbackSpeed: Double=1.0
}
Test names describe behavior: func test_login_withExpiredToken_refreshesAutomatically()
Use setUp() / tearDown() for shared test fixtures
Use protocol-based mocks injected via initializer (no singletons)
Async tests use async throws directly (no XCTestExpectation for async/await code)
Coverage target: >80% for business logic, >60% overall
Test both success and failure paths for every public method
Tooling
Essential Commands
swift build # Build all targets
swift test# Run all tests
swift test --enable-code-coverage # With coverage
swift package resolve # Resolve dependencies
swift package update # Update dependencies
swift format . # Format (swift-format)
swiftlint # Lint (SwiftLint)
swiftlint --fix # Auto-fix lint issues
SwiftLint Key Rules
# .swiftlint.yml -- enforce these as errorsforce_cast:errorforce_unwrapping:errorforce_try:errorfunction_body_length:warning:40error:50cyclomatic_complexity:warning:8error:10